Skip to content

Commit d7d32d8

Browse files
committed
Safe using include_gon method
1 parent c84a69a commit d7d32d8

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

lib/gon/helpers.rb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,18 @@ def self.included base
66

77
module InstanceMethods
88
def include_gon
9-
data = Gon.all_variables
9+
if Gon.request_env
10+
data = Gon.all_variables
1011

11-
script = "<script>window.gon = {};"
12-
data.each do |key, val|
13-
script += "gon." + key.to_s + '=' + val.to_json + ";"
12+
script = "<script>window.gon = {};"
13+
data.each do |key, val|
14+
script += "gon." + key.to_s + '=' + val.to_json + ";"
15+
end
16+
script += "</script>"
17+
script.html_safe
18+
else
19+
""
1420
end
15-
script += "</script>"
16-
script.html_safe
1721
end
1822
end
1923
end

0 commit comments

Comments
 (0)