3,102
Stars
185
Forks
47
Watchers
45
Open Issues
MIT
许可证
Ruby
语言
2011-05-09
创建时间
2026-11-08
最近更新
项目能做什么
将 Rails 变量直接传递给 JavaScript 的工具。
来源:基于仓库元数据
· 内容以仓库实际 README 为准
使用说明 查看原始 README 原仓库文档
中文使用说明暂未生成。下面保留原仓库 README 摘录,命令与配置均以原文为准。
原始 README 摘录(英文原文,节选前 3000 字符)
# Gon gem — get your Rails variables in your js

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](https://github.com/gazay/gon/wiki/Usage-gon-watch)!
With [Jbuilder](https://github.com/rails/jbuilder) and [Rabl](https://github.com/nesquena/rabl) support!
For Sinatra available [gon-sinatra](https://github.com/gazay/gon-sinatra).
For .Net MVC available port [NGon](https://github.com/brooklynDev/NGon).
For elixir Phoenix available [PhoenixGon](https://github.com/khusnetdinov/phoenix_gon).
<a href="https://evilmartians.com/?utm_source=gon">
<img src="https://evilmartians.com/badges/sponsored-by-evil-martians.svg" alt="Sponsored by Evil Martians" width="236" height="54">
</a>
## An example of typical use
### Very good and detailed example and reasons to use is considered in [railscast](http://railscasts.com/episodes/324-passing-data-to-javascript) 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
``` ruby
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
```
2. In your js you get this by
``` js
gon.variable_name
```
3. 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](https://github.com/gazay/gon/wiki)
`app/views/layouts/application.html.erb`
``` erb
<head>
<title>some title</title>
<%= Gon::Base.render_data %>
<!-- include your action js code -->
...
```
For rails 3:
``` erb
<%= include_gon %>
...
```
You can pass some [options](https://github.com/gazay/gon/wiki/Options)
to `render_data` method.
You put something like this in the action of your controlle
阅读完整原文
项目深度分析 规则生成(AI 未配置)
综合评分 45.5 分。该项目在“个人可实施性”维度得 45 分,“付费可能性”维度得 20.0 分,差异化空间 70.0 分(评分依据见评分卡)。
面向细分需求的二次开发产品
| 产品构想 | 基于 gon 的核心能力,聚焦一个更窄的场景(如某平台、某行业)做差异化。 |
| 目标用户 | 该细分场景用户 |
| 难度/周期 | 中 · 2~6 周 |
| 收费模式 | 买断制 / 订阅制 / 广告 |
| 竞争风险 | 细分需求规模需验证 |
| 依据 | AI 推测:基于项目主题标签的判断 |
以上为规则引擎基于仓库公开数据生成的参考结论,包含推测成分,不构成投资或创业承诺;配置 AI 后可获得更深入的分析。
报告会保存到 个人中心
竞品与相似项目 GitHub Search 真实检索
以上为通过 GitHub 官方 Search API 检索的相似项目,功能差异与优劣势需进一步人工确认,配置 AI 后可生成对比分析。
项目优势与风险
| 技术成熟度 | 创建于 2011-05-09,近 30 天仍在推送,发布过 5 个 Release |
| 社区活跃 | Star 3,102 / Fork 185 / Issue 45(数据支持,可自行核实) |
| 许可证 | MIT |
| 主要风险 | 上游项目方向可能变化;同赛道竞争者较多(见竞品表);热度与需求不完全等价 |
安装与使用
此项目未提供 Docker 镜像,安装步骤以原仓库 README 为准(涉及依赖安装与环境配置,对新手门槛较高)。