File tree Expand file tree Collapse file tree 3 files changed +13
-1
lines changed
Expand file tree Collapse file tree 3 files changed +13
-1
lines changed Original file line number Diff line number Diff 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+
8595You can get json without script tag (kudos to @afa ):
8696
8797` ` ` erb
Original file line number Diff line number Diff 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 ""
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments