Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 71 lines (47 sloc) 2.261 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>
83b22e3 @gazay Js generation
authored
12 <%= include_gon %>
13 <!-- include your action js code -->
020007b @gazay Added description and usage
authored
14 ...
15 ```
16
17 In action of your controller you put something like this:
18
19 ``` ruby
a4f0807 @gazay Added types to description
authored
20 @your_int = 123
21 @your_array = [1,2]
22 @your_hash = {'a' => 1, 'b' => 2}
23 Gon.your_int = @your_int
24 Gon.your_other_int = 345 + @your_int
25 Gon.your_array = @your_array
26 Gon.your_hash = @your_hash
020007b @gazay Added description and usage
authored
27 ```
28
29 In javascript file for view of this action write call to your variable:
30
31 ``` js
a4f0807 @gazay Added types to description
authored
32 alert(Gon.your_int)
33 alert(Gon.your_other_int)
34 alert(Gon.your_array)
35 alert(Gon.your_hash)
020007b @gazay Added description and usage
authored
36 ```
89df60b @gazay Initial commit
authored
37
38 ## Installation
39
40 Puts this line into `Gemfile` then run `$ bundle`:
41
42 ``` ruby
3312851 @gazay Adding types support
authored
43 gem 'gon', '0.2.1'
89df60b @gazay Initial commit
authored
44 ```
45
46 Or if you are old-school Rails 2 developer put this into `config/environment.rb` and run `$ rake gems:install`:
47
48 ``` ruby
3312851 @gazay Adding types support
authored
49 config.gem 'gon', :version => '0.2.1'
89df60b @gazay Initial commit
authored
50 ```
51
da310ad @gazay Edited README.md via GitHub
authored
52 Or manually install gon gem: `$ gem install gon`
89df60b @gazay Initial commit
authored
53
54 ## Contributors
55
56 * @gazay
57
2f1bc0e @gazay Edited README.md via GitHub
authored
58 Special thanks to @brainopia, @kossnocorp and @ai.
89df60b @gazay Initial commit
authored
59
60 ## License
61
62 The MIT License
63
64 Copyright (c) 2011 gazay
65
66 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:
67
68 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
69
70 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.