A Ruby gem that seamlessly passes Rails controller variables to JavaScript, eliminating the need for data attributes or inline scripts.
Gon is a Ruby gem that provides a simple and efficient way to pass data from Rails controllers directly to JavaScript. It solves the problem of cluttering views with data attributes or inline scripts by allowing developers to assign variables in controllers and access them via a global `gon` object in JavaScript. This streamlines frontend-backend communication and supports live updates through AJAX.
Rails developers who need to share server-side data with JavaScript in their views, especially those building dynamic, real-time web applications without heavy frontend frameworks.
Developers choose Gon because it eliminates the boilerplate of manually embedding data in HTML attributes or writing inline JavaScript, offering a cleaner, more maintainable approach. Its integration with popular template engines like Jbuilder and Rabl, along with features like `gon.watch` for live updates, makes it a versatile tool for modern Rails applications.
Your Rails variables in your JS
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Allows assigning Ruby variables in controllers and accessing them instantly in JavaScript via the global `gon` object, eliminating the need for inline scripts or data attributes, as shown in the README examples.
Features `gon.watch` for automatic AJAX-based data refreshes without page reloads, making it ideal for real-time applications like dashboards, with detailed usage instructions in the wiki.
Integrates seamlessly with Jbuilder, Rabl, and Rabl-Rails for data serialization, enabling cleaner controllers by moving logic to view templates, as highlighted in the README sections.
Includes the `include_gon_amd` helper for projects using RequireJS or similar AMD systems, providing flexibility for different JavaScript architectures.
Supports multiple JSON engines via MultiJson, allowing developers to choose the fastest option for their environment, as mentioned in the speed-up section.
Relies on a global `gon` object, which can lead to namespace conflicts and make code harder to maintain and test in larger, more complex JavaScript applications.
Primarily built for Rails, with ports for other frameworks like Sinatra or .Net but not as deeply integrated, limiting its usefulness in polyglot or non-Rails projects.
Advanced features such as `gon.watch` and template engine usage require additional setup and reference to external wiki pages, adding to the initial learning curve and potential for misconfiguration.
Injecting data directly from controllers to JavaScript without built-in security measures risks exposing sensitive information if developers are not vigilant about filtering data.