Skip to content
Newer
Older
100644 66 lines (42 sloc) 2.21 KB
89df60b @gazay Initial commit
authored
1 # Gon gem — get your Rails variables in your js
2
020007b @gazay Added description and usage
authored
3 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!
89df60b @gazay Initial commit
authored
4
5 ## Usage
6
020007b @gazay Added description and usage
authored
7 `app/views/layouts/application.html.erb`
8
9 ``` erb
10 <head>
11 <title>some title</title>
12 <gon style='display:none'><%= gon_variables %></gon>
13 <%= javascript_include_tag 'http://code.jquery.com/jquery-1.6.min.js' %> <!-- include jquery -->
14 <%= include_gon %>
15 ...
16 ```
17
18 In action of your controller you put something like this:
19
20 ``` ruby
21 @your_variable = 123
22 Gon.your_variable = @your_variable
23 Gon.your_other_variable = 345 + @your_variable
24 ```
25
26 In javascript file for view of this action write call to your variable:
27
28 ``` js
29 alert(Gon.your_variable)
30 alert(Gon.your_other_variable)
31 ```
89df60b @gazay Initial commit
authored
32
33 ## Installation
34
35 Puts this line into `Gemfile` then run `$ bundle`:
36
37 ``` ruby
38 gem 'gon', '0.1.0'
39 ```
40
41 Or if you are old-school Rails 2 developer put this into `config/environment.rb` and run `$ rake gems:install`:
42
43 ``` ruby
44 config.gem 'gon', :version => '0.1.0'
45 ```
46
47 Or manually install variants gem: `$ gem install gon`
48
49 ## Contributors
50
51 * @gazay
52
53 Special thanks to @brainopia and @kossnocorp.
54
55 ## License
56
57 The MIT License
58
59 Copyright (c) 2011 gazay
60
61 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
62
63 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
64
65 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Something went wrong with that request. Please try again.