9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/gon/helpers.rb', line 9
def include_gon(options = {})
if Gon.request_env && Gon.all_variables.present?
data = Gon.all_variables
namespace = options[:namespace] || 'gon'
script = '<script>window.' + namespace + ' = {};'
if options[:camel_case]
data.each do |key, val|
script << namespace + '.' + key.to_s.camelize(:lower) + '=' + val.to_json + ';'
end
else
data.each do |key, val|
script << namespace + '.' + key.to_s + '=' + val.to_json + ';'
end
end
script << '</script>'
script.html_safe
else
""
end
end
|