A summary of data about the Ruby ecosystem.

https://github.com/gazay/gon

Your Rails variables in your JS
https://github.com/gazay/gon

Keywords from Contributors

activerecord activejob mvc rspec rubygems rack ruby-gem crash-reporting sinatra error-monitoring

Last synced: about 18 hours ago
JSON representation

Repository metadata

Your Rails variables in your JS

README.md

Gon gem — get your Rails variables in your js

Gon. You should try this. If you look closer - you will see an elephant.

If you need to send some data to your js files and you don't want to do this with long way through views and parsing - use this force!

Now you can easily renew data in your variables through ajax with gon.watch!

With Jbuilder, Rabl, and Rabl-Rails support!

For Sinatra available gon-sinatra.

For .Net MVC available port NGon.

For elixir Phoenix available PhoenixGon.

An example of typical use

Very good and detailed example and reasons to use is considered in railscast by Ryan Bates

When you need to send some start data from your controller to your js
you might be doing something like this:

  1. Write this data in controller(presenter/model) to some variable
  2. In view for this action you put this variable to some objects by data
    attributes, or write js right in view
  3. Then there can be two ways in js:
    + if you previously wrote data in data
    attributes - you should parse this attributes and write data to some
    js variable.
    + if you wrote js right in view (many frontenders would shame you for
    that) - you just use data from this js - OK.
  4. You can use your data in your js

And every time when you need to send some data from action to js you do this.

With gon you configure it firstly - just put in layout one tag, and add
gem line to your Gemfile and do the following:

  1. Write variables by
 gon.variable_name = variable_value

 # or new syntax
 gon.push({
   :user_id => 1,
   :user_role => "admin"
 })

 gon.push(any_object) # any_object with respond_to? :each_pair
  1. In your js you get this by
 gon.variable_name
  1. profit?

With the gon.watch feature you can easily renew data in gon variables!
Simply call gon.watch from your js file. It's super useful
in modern web applications!

Usage

More details about configuration and usage you can find in gon wiki

app/views/layouts/application.html.erb

<head>
  <title>some title</title>
  <%= Gon::Base.render_data %>
  <!-- include your action js code -->
  ...

For rails 3:

  <%= include_gon %>
  ...

You can pass some options
to render_data method.

You put something like this in the action of your controller:

@your_int = 123
@your_array = [1,2]
@your_hash = {'a' => 1, 'b' => 2}
gon.your_int = @your_int
gon.your_other_int = 345 + gon.your_int
gon.your_array = @your_array
gon.your_array << gon.your_int
gon.your_hash = @your_hash

gon.all_variables # > {:your_int => 123, :your_other_int => 468, :your_array => [1, 2, 123], :your_hash => {'a' => 1, 'b' => 2}}
gon.your_array # > [1, 2, 123]

# gon.clear # gon.all_variables now is {}

Access the variables from your JavaScript file:

alert(gon.your_int)
alert(gon.your_other_int)
alert(gon.your_array)
alert(gon.your_hash)

AMD compatible version: include_gon_amd

If your site uses AMD modules you can use the include_gon_amd helper to
include the variables and watch function as a module. Options are mostly
the same as for include_gon, except for namespace_check, which does
nothing and namespace, which is used as the name of the defined module.
The end result will look somewhat like the following:

define('yourNameSpace', [], function() {
  var gon = {};
  gon.yourVariable = yourValue;
  // etc...

  return gon;
});

A (very) simplified usage example:

app/views/layouts/application.html.erb

include_gon_amd namespace: 'data'

Some JavaScript module

define(['data'], function(data) {
  alert(data.myVariable);
});

gon.watch - renew your data easily!

You can use gon for renewing your data without reloading pages and
writing long js functions! It's really great for some live values.

Supports gon.watch.rabl and gon.watch.jbuilder usage.

Instruction for
usage gon.watch.

Usage with Rabl

You can write your variables assign logic to templates with Rabl.
The way of writing Rabl templates is very clearly described in their repo.

Profit of using Rabl with gon:

  1. You can clean your controllers now!
  2. Work with database objects and collections clearly and easyly
  3. All power of Rabl
  4. You can still be lazy and don't use common way to transfer data in js
  5. And so on

Instruction for
usage gon with Rabl.

Usage with Rabl-Rails

gon.rabl works with rabl-rails. Learn to write RABL the rabl-rails way here.

Add gon and rabl-rails to your environment:

gem 'gon'
gem 'rabl-rails'

Define a rabl template using rabl-rails syntax:

#app/views/users/show.rabl
object :@user
attributes :id, :name, :email, :location

Call gon.rabl in your controller

#app/controllers/users_controller.rb
def show
  @user = User.find(params[:id])
  gon.rabl
end

Usage with Jbuilder

Use gon with Jbuilder as with Rabl:

Instruction for
usage gon with Jbuilder.

gon.global

You can use gon for sending your data to js from anywhere! It's really
great for some init data.

Instruction for
usage gon.global.

Speed up Gon

You can use any JSON Engine you want.
Gon uses MultiJson with autodetect mode, so all you need is just require your JSON library.

Current Maintainers

Special thanks

  • @takiy33
  • @brainopia
  • @kossnocorp
  • @ai

Original Author

License

The MIT License

Security Contact

To report a security vulnerability, please use the Tidelift security contact. Tidelift will coordinate the fix and disclosure.


Owner metadata


GitHub Events

Total
Last Year

Committers metadata

Last synced: 2 days ago

Total Commits: 406
Total Committers: 72
Avg Commits per committer: 5.639
Development Distribution Score (DDS): 0.466

Commits in past year: 33
Committers in past year: 3
Avg Commits per committer in past year: 11.0
Development Distribution Score (DDS) in past year: 0.212

Name Email Commits
Alexey Gaziev a****v@g****m 217
Shinichi Maeshima n****t@g****m 26
takiy33 t****3@g****m 23
takiy33 t****3 21
Vlad Bokov r****m@m****u 8
Maksim Berjoza t****n@g****m 7
krororo k****7@g****m 5
Peter M. Goldstein p****n@g****m 5
Hector Satre m****n@g****m 5
Strech (Sergey Fedorov) s****f@m****u 4
Edward Tsech e****h@g****m 3
Arsen Gasparyan b****1@g****m 3
Alex Rakoczy s****r@g****m 3
Ellis Berner e****r@g****m 3
John Therrell j****l@g****m 3
novoi i****v@p****m 3
Scott Yoder y****b@g****m 2
Rafael Liu r****u@g****m 2
Philippe Vaucher p****e@s****h 2
Peter Schröder p****l@g****m 2
Nicolas Leger n****r 2
Graeme Longman g****n@g****m 2
Tom Hallett t****t@g****m 2
Ville Kukkonen k****e@g****m 2
Will Cosgrove w****l@w****m 2
Yuri Zubov y****v@c****o 2
aekym me@a****m 2
Akira Matsuda r****e@d****p 1
Artur Sabrov s****j@g****m 1
Andreas Salme a****e@y****m 1
and 42 more...

Committer domains:


Issue and Pull Request metadata

Last synced: 9 days ago

Total issues: 80
Total pull requests: 47
Average time to close issues: 11 months
Average time to close pull requests: 4 months
Total issue authors: 75
Total pull request authors: 30
Average comments per issue: 3.18
Average comments per pull request: 1.0
Merged pull request: 30
Bot issues: 0
Bot pull requests: 0

Past year issues: 1
Past year pull requests: 20
Past year average time to close issues: N/A
Past year average time to close pull requests: 10 days
Past year issue authors: 1
Past year pull request authors: 5
Past year average comments per issue: 0.0
Past year average comments per pull request: 0.4
Past year merged pull request: 11
Past year bot issues: 0
Past year bot pull requests: 0

More stats: https://issues.ecosyste.ms/repositories/lookup?url=https://github.com/gazay/gon

Top Issue Authors

  • pravi (3)
  • justin808 (2)
  • nov (2)
  • RavenXce (2)
  • brian-mann (1)
  • didil (1)
  • ggrillone (1)
  • ertrzyiks (1)
  • stoplion (1)
  • nullnull (1)
  • etagwerker (1)
  • rubydesign (1)
  • corporealfunk (1)
  • devopsjourney1 (1)
  • almog (1)

Top Pull Request Authors

  • willnet (12)
  • krororo (3)
  • shogo-08020318 (2)
  • yuri-zubov (2)
  • dee-see (2)
  • Faq (2)
  • ojab (1)
  • 513ry (1)
  • amatsuda (1)
  • etipton (1)
  • vlazar (1)
  • cristina23 (1)
  • ertrzyiks (1)
  • wilddima (1)
  • khusnetdinov (1)

Top Issue Labels

Top Pull Request Labels


Package metadata

gem.coop: gon

If you need to send some data to your js files and you don't want to do this with long way trough views and parsing - use this force!

  • Homepage: https://github.com/gazay/gon
  • Documentation: http://www.rubydoc.info/gems/gon/
  • Licenses: MIT
  • Latest release: 7.0.0 (published about 2 months ago)
  • Last Synced: 2026-03-01T15:31:38.887Z (2 days ago)
  • Versions: 57
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 61,973,052 Total
  • Docker Downloads: 461,298,708
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 0.171%
    • Docker downloads count: 0.237%
    • Downloads: 0.446%
  • Maintainers (2)
  • Advisories:
rubygems.org: gon

If you need to send some data to your js files and you don't want to do this with long way trough views and parsing - use this force!

  • Homepage: https://github.com/gazay/gon
  • Documentation: http://www.rubydoc.info/gems/gon/
  • Licenses: MIT
  • Latest release: 7.0.0 (published about 2 months ago)
  • Last Synced: 2026-03-01T09:41:29.215Z (2 days ago)
  • Versions: 57
  • Dependent Packages: 26
  • Dependent Repositories: 6,597
  • Downloads: 61,971,134 Total
  • Docker Downloads: 461,298,708
  • Rankings:
    • Docker downloads count: 0.292%
    • Dependent repos count: 0.396%
    • Downloads: 0.468%
    • Stargazers count: 0.652%
    • Average: 0.751%
    • Dependent packages count: 0.873%
    • Forks count: 1.826%
  • Maintainers (1)
  • Advisories:
proxy.golang.org: github.com/gazay/gon

  • Homepage:
  • Documentation: https://pkg.go.dev/github.com/gazay/gon#section-documentation
  • Licenses: mit
  • Latest release: v7.0.0+incompatible (published about 2 months ago)
  • Last Synced: 2026-02-28T23:00:55.248Z (3 days ago)
  • Versions: 56
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent packages count: 6.521%
    • Average: 6.74%
    • Dependent repos count: 6.959%
ubuntu-24.04: ruby-gon

  • Homepage: https://github.com/gazay/gon
  • Licenses:
  • Latest release: 6.4.0-2 (published 25 days ago)
  • Last Synced: 2026-02-06T15:17:13.761Z (25 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
debian-10: ruby-gon

  • Homepage: https://github.com/gazay/gon
  • Documentation: https://packages.debian.org/buster/ruby-gon
  • Licenses:
  • Latest release: 6.2.1-1 (published 20 days ago)
  • Last Synced: 2026-02-13T04:21:55.462Z (19 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
ubuntu-23.04: ruby-gon

  • Homepage: https://github.com/gazay/gon
  • Licenses:
  • Latest release: 6.4.0-2 (published 20 days ago)
  • Last Synced: 2026-02-11T06:40:17.949Z (20 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
ubuntu-23.10: ruby-gon

  • Homepage: https://github.com/gazay/gon
  • Licenses:
  • Latest release: 6.4.0-2 (published 18 days ago)
  • Last Synced: 2026-02-13T18:21:11.919Z (18 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
ubuntu-24.10: ruby-gon

  • Homepage: https://github.com/gazay/gon
  • Licenses:
  • Latest release: 6.4.0-2 (published 22 days ago)
  • Last Synced: 2026-02-09T16:36:50.697Z (22 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
debian-11: ruby-gon

  • Homepage: https://github.com/gazay/gon
  • Documentation: https://packages.debian.org/bullseye/ruby-gon
  • Licenses:
  • Latest release: 6.4.0-1 (published 21 days ago)
  • Last Synced: 2026-02-13T08:20:40.409Z (18 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
ubuntu-20.04: ruby-gon

  • Homepage: https://github.com/gazay/gon
  • Licenses:
  • Latest release: 6.3.2-1 (published 18 days ago)
  • Last Synced: 2026-02-13T07:14:29.285Z (18 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
ubuntu-22.04: ruby-gon

  • Homepage: https://github.com/gazay/gon
  • Licenses:
  • Latest release: 6.4.0-2 (published 18 days ago)
  • Last Synced: 2026-02-13T13:17:42.229Z (18 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
debian-12: ruby-gon

  • Homepage: https://github.com/gazay/gon
  • Documentation: https://packages.debian.org/bookworm/ruby-gon
  • Licenses:
  • Latest release: 6.4.0-2 (published 19 days ago)
  • Last Synced: 2026-02-12T23:30:20.138Z (19 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:

Dependencies

gon.gemspec rubygems
  • jbuilder >= 0 development
  • pry >= 0 development
  • pry-byebug >= 0 development
  • rabl = 0.11.3 development
  • rabl-rails >= 0 development
  • railties >= 3.0.20 development
  • rake >= 0 development
  • rspec >= 3.0 development
  • actionpack >= 3.0.20
  • i18n >= 0.7
  • multi_json >= 0
  • request_store >= 1.0
.github/workflows/ci.yml actions
  • actions/checkout v5 composite
  • ruby/setup-ruby v1 composite
Gemfile rubygems

Score: 33.09261924627365