[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-7876":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":16,"stars7d":16,"stars30d":17,"stars90d":16,"forks30d":16,"starsTrendScore":16,"compositeScore":18,"rankGlobal":10,"rankLanguage":10,"license":19,"archived":20,"fork":20,"defaultBranch":21,"hasWiki":22,"hasPages":22,"topics":23,"createdAt":10,"pushedAt":10,"updatedAt":24,"readmeContent":25,"aiSummary":26,"trendingCount":16,"starSnapshotCount":16,"syncStatus":27,"lastSyncTime":28,"discoverSource":29},7876,"gon","gazay\u002Fgon","gazay","Your Rails variables in your JS","",null,"Ruby",3099,186,49,40,0,12,60.02,"MIT License",false,"master",true,[],"2026-06-12 04:00:36","# Gon gem — get your Rails variables in your js\n\n![Gon. You should try this. If you look closer - you will see an elephant.](https:\u002F\u002Fgithub.com\u002Fgazay\u002Fgon\u002Fraw\u002Fmaster\u002Fdoc\u002Flogo_small.png)\n\nIf 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!\n\nNow you can easily renew data in your variables through ajax with [gon.watch](https:\u002F\u002Fgithub.com\u002Fgazay\u002Fgon\u002Fwiki\u002FUsage-gon-watch)!\n\nWith [Jbuilder](https:\u002F\u002Fgithub.com\u002Frails\u002Fjbuilder), [Rabl](https:\u002F\u002Fgithub.com\u002Fnesquena\u002Frabl), and [Rabl-Rails](https:\u002F\u002Fgithub.com\u002Fccocchi\u002Frabl-rails) support!\n\nFor Sinatra available [gon-sinatra](https:\u002F\u002Fgithub.com\u002Fgazay\u002Fgon-sinatra).\n\nFor .Net MVC available port [NGon](https:\u002F\u002Fgithub.com\u002FbrooklynDev\u002FNGon).\n\nFor elixir Phoenix available [PhoenixGon](https:\u002F\u002Fgithub.com\u002Fkhusnetdinov\u002Fphoenix_gon).\n\n\u003Ca href=\"https:\u002F\u002Fevilmartians.com\u002F?utm_source=gon\">\n\u003Cimg src=\"https:\u002F\u002Fevilmartians.com\u002Fbadges\u002Fsponsored-by-evil-martians.svg\" alt=\"Sponsored by Evil Martians\" width=\"236\" height=\"54\">\n\u003C\u002Fa>\n\n## An example of typical use\n\n### Very good and detailed example and reasons to use is considered in [railscast](http:\u002F\u002Frailscasts.com\u002Fepisodes\u002F324-passing-data-to-javascript) by Ryan Bates\n\nWhen you need to send some start data from your controller to your js\nyou might be doing something like this:\n\n  1. Write this data in controller(presenter\u002Fmodel) to some variable\n  2. In view for this action you put this variable to some objects by data\n     attributes, or write js right in view\n  3. Then there can be two ways in js:\n    + if you previously wrote data in data\n     attributes - you should parse this attributes and write data to some\n     js variable.\n    + if you wrote js right in view (many frontenders would shame you for\n  that) - you just use data from this js - OK.\n  4. You can use your data in your js\n\nAnd every time when you need to send some data from action to js you do this.\n\nWith gon you configure it firstly - just put in layout one tag, and add\ngem line to your Gemfile and do the following:\n\n  1. Write variables by\n\n   ``` ruby\n    gon.variable_name = variable_value\n\n    # or new syntax\n    gon.push({\n      :user_id => 1,\n      :user_role => \"admin\"\n    })\n\n    gon.push(any_object) # any_object with respond_to? :each_pair\n   ```\n\n  2. In your js you get this by\n\n   ``` js\n    gon.variable_name\n   ```\n\n  3. profit?\n\nWith the `gon.watch` feature you can easily renew data in gon variables!\nSimply call `gon.watch` from your js file. It's super useful\nin modern web applications!\n\n## Usage\n\n### More details about configuration and usage you can find in [gon wiki](https:\u002F\u002Fgithub.com\u002Fgazay\u002Fgon\u002Fwiki)\n\n`app\u002Fviews\u002Flayouts\u002Fapplication.html.erb`\n\n``` erb\n\u003Chead>\n  \u003Ctitle>some title\u003C\u002Ftitle>\n  \u003C%= Gon::Base.render_data %>\n  \u003C!-- include your action js code -->\n  ...\n```\n\nFor rails 3:\n``` erb\n  \u003C%= include_gon %>\n  ...\n```\n\n\n\nYou can pass some [options](https:\u002F\u002Fgithub.com\u002Fgazay\u002Fgon\u002Fwiki\u002FOptions)\nto `render_data` method.\n\nYou put something like this in the action of your controller:\n\n``` ruby\n@your_int = 123\n@your_array = [1,2]\n@your_hash = {'a' => 1, 'b' => 2}\ngon.your_int = @your_int\ngon.your_other_int = 345 + gon.your_int\ngon.your_array = @your_array\ngon.your_array \u003C\u003C gon.your_int\ngon.your_hash = @your_hash\n\ngon.all_variables # > {:your_int => 123, :your_other_int => 468, :your_array => [1, 2, 123], :your_hash => {'a' => 1, 'b' => 2}}\ngon.your_array # > [1, 2, 123]\n\n# gon.clear # gon.all_variables now is {}\n```\n\nAccess the variables from your JavaScript file:\n\n``` js\nalert(gon.your_int)\nalert(gon.your_other_int)\nalert(gon.your_array)\nalert(gon.your_hash)\n```\n\n### AMD compatible version: `include_gon_amd`\n\nIf your site uses AMD modules you can use the `include_gon_amd` helper to\ninclude the variables and watch function as a module. Options are mostly\nthe same as for `include_gon`, except for `namespace_check`, which does\nnothing and `namespace`, which is used as the name of the defined module.\nThe end result will look somewhat like the following:\n\n```js\ndefine('yourNameSpace', [], function() {\n  var gon = {};\n  gon.yourVariable = yourValue;\n  \u002F\u002F etc...\n\n  return gon;\n});\n```\n\nA (very) simplified usage example:\n\n`app\u002Fviews\u002Flayouts\u002Fapplication.html.erb`\n\n```ruby\ninclude_gon_amd namespace: 'data'\n```\n\n`Some JavaScript module`\n\n```js\ndefine(['data'], function(data) {\n  alert(data.myVariable);\n});\n```\n\n## gon.watch - renew your data easily!\n\nYou can use gon for renewing your data without reloading pages and\nwriting long js functions! It's really great for some live values.\n\nSupports `gon.watch.rabl` and `gon.watch.jbuilder` usage.\n\n[Instruction](https:\u002F\u002Fgithub.com\u002Fgazay\u002Fgon\u002Fwiki\u002FUsage-gon-watch) for\nusage gon.watch.\n\n## Usage with Rabl\n\nYou can write your variables assign logic to templates with [Rabl](https:\u002F\u002Fgithub.com\u002Fnesquena\u002Frabl).\nThe way of writing Rabl templates is very clearly described in their repo.\n\nProfit of using Rabl with gon:\n\n  1. You can clean your controllers now!\n  2. Work with database objects and collections clearly and easyly\n  3. All power of Rabl\n  4. You can still be lazy and don't use common way to transfer data in js\n  5. And so on\n\n[Instruction](https:\u002F\u002Fgithub.com\u002Fgazay\u002Fgon\u002Fwiki\u002FUsage-with-rabl) for\nusage gon with Rabl.\n\n## Usage with Rabl-Rails\n`gon.rabl` works with [rabl-rails](https:\u002F\u002Fgithub.com\u002Fccocchi\u002Frabl-rails). Learn to write RABL the rabl-rails way [here](https:\u002F\u002Fgithub.com\u002Fccocchi\u002Frabl-rails).\n\nAdd gon and rabl-rails to your environment:\n```ruby\ngem 'gon'\ngem 'rabl-rails'\n```\nDefine a rabl template using rabl-rails syntax:\n```rabl\n#app\u002Fviews\u002Fusers\u002Fshow.rabl\nobject :@user\nattributes :id, :name, :email, :location\n```\nCall gon.rabl in your controller\n\n```ruby\n#app\u002Fcontrollers\u002Fusers_controller.rb\ndef show\n  @user = User.find(params[:id])\n  gon.rabl\nend\n```\n\n## Usage with Jbuilder\n\nUse gon with [Jbuilder](https:\u002F\u002Fgithub.com\u002Frails\u002Fjbuilder) as with [Rabl](https:\u002F\u002Fguthub.com\u002Fnesquena\u002Frabl):\n\n[Instruction](https:\u002F\u002Fgithub.com\u002Fgazay\u002Fgon\u002Fwiki\u002FUsage-with-jbuilder) for\nusage gon with Jbuilder.\n\n## gon.global\n\nYou can use gon for sending your data to js from anywhere! It's really\ngreat for some init data.\n\n[Instruction](https:\u002F\u002Fgithub.com\u002Fgazay\u002Fgon\u002Fwiki\u002FUsage-gon-global) for\nusage gon.global.\n\n## Speed up Gon\n\nYou can use any [JSON Engine](https:\u002F\u002Fgithub.com\u002Fsferik\u002Fmulti_json#supported-json-engines) you want.\nGon uses `MultiJson` with autodetect mode, so all you need is just require your JSON library.\n\n## Current Maintainers\n\n* [@willnet](https:\u002F\u002Fgithub.com\u002Fwillnet)\n\n## Special thanks\n\n* @takiy33\n* @brainopia\n* @kossnocorp\n* @ai\n\n## Original Author\n\n* [@gazay](https:\u002F\u002Fgithub.com\u002Fgazay)\n\n## License\n\nThe MIT License\n\n## Security Contact\n\nTo report a security vulnerability, please use the [Tidelift security contact](https:\u002F\u002Ftidelift.com\u002Fsecurity). Tidelift will coordinate the fix and disclosure.\n","Gon 是一个 Ruby gem，用于将 Rails 变量直接传递给 JavaScript。它简化了从后端到前端的数据传输过程，避免了通过视图和解析的繁琐步骤。Gon 支持 Jbuilder、Rabl 和 Rabl-Rails 等数据序列化工具，并且具备 `gon.watch` 功能，可以轻松更新变量中的数据。此外，Gon 还为 Sinatra、.Net MVC 以及 Elixir Phoenix 提供了相应的版本。该项目适用于需要在 Rails 应用中高效地向 JavaScript 传递初始数据或动态更新数据的场景，尤其适合现代 Web 应用开发。",2,"2026-06-11 03:14:50","top_language"]