Skip to content

Commit c6001b6

Browse files
committed
added comment to documentation and Gon.clear if variables exists
1 parent 015a8eb commit c6001b6

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,16 @@ You can change the namespace of the variables:
8282
...
8383
```
8484

85+
You can initialize window.gon = {}; on each request
86+
87+
``` erb
88+
<head>
89+
<title>some title</title>
90+
<%= include_gon(:init => true) %>
91+
<!-- include your action js code with 'serverExports' namespace -->
92+
...
93+
```
94+
8595
You can get json without script tag (kudos to @afa):
8696

8797
``` erb

lib/gon/helpers.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def include_gon(options = {})
1414
Gon.clear
1515
Gon::Base.render_data(options)
1616
elsif options[:init].present?
17+
Gon.clear if Gon.all_variables.present?
1718
Gon::Base.render_data(options)
1819
else
1920
""

spec/gon/basic_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@
8181

8282

8383
it 'outputs correct js without variables, without tag and gon init' do
84-
@base.include_gon(need_tag: false, init: true).should == 'window.gon = {};'
84+
@base.include_gon(need_tag: false, init: true).should == \
85+
'window.gon = {};'
8586
end
8687

8788
it 'outputs correct js without variables, without tag and gon init' do

0 commit comments

Comments
 (0)