Gon

screenshot of Gon

Your Rails variables in your JS

Overview

The Gon gem is a powerful tool for Ruby on Rails developers looking to simplify the process of sending data to JavaScript. Traditionally, passing variables from the server to the client required cumbersome methods, including writing inline JavaScript or using data attributes. With Gon, you can effortlessly integrate your Rails variables into your JavaScript code, enhancing both efficiency and readability.

One of the standout features of the Gon gem is its ability to update JavaScript variables seamlessly through AJAX without the need for page reloads. This is particularly useful in modern web applications that demand real-time functionalities. Whether you’re using frameworks like Jbuilder, Rabl, or even Sinatra, Gon ensures that your data flow between the backend and frontend remains smooth and manageable.

Features

  • Easy Integration: Just add a single tag to your layout and include the gem in your Gemfile to get started quickly.
  • Automatic Data Updates: Utilize gon.watch to automatically refresh your JavaScript variables, eliminating the need for page reloads.
  • Framework Compatibility: Supports popular frameworks including Jbuilder and Rabl, making it versatile for various project architectures.
  • AMD Module Support: For sites using AMD modules, Gon can be included as a module, facilitating a clean integration into your JavaScript structure.
  • Streamlined Controllers: Helps clean up your Rails controllers by allowing you to handle data rendering directly through templates, keeping your codebase organized.
  • Seamless Live Updates: Perfect for applications needing real-time data, allowing you to work with live values without lengthy JavaScript functions.
  • Rich Documentation: Comprehensive and detailed usage examples are available, making it easy for developers to implement and troubleshoot.
  • Cross-Framework Availability: Available ports for other frameworks such as NGon for .Net MVC and PhoenixGon for Elixir, broadening its usability across different platforms.