lib/gon/helpers.rb in gon-1.0.0 vs lib/gon/helpers.rb in gon-1.1.0

- old
+ new

@@ -4,20 +4,35 @@ base.send(:include, InstanceMethods) end module InstanceMethods def include_gon - data = Gon.all_variables || {} + data = Gon.all_variables - script = "<script>window.Gon = {};" + script = "<script>window.gon = {};" data.each do |key, val| - script += "Gon." + key.to_s + '=' + val.to_json + ";" + script += "gon." + key.to_s + '=' + val.to_json + ";" end script += "</script>" script.html_safe end end + end + module GonHelpers + def self.included base + base.send(:include, InstanceMethods) + end + + module InstanceMethods + def gon + if !Gon.request_env || Gon.request_env.object_id != request.env.object_id + Gon.request_env = request.env + end + Gon + end + end end end ActionView::Base.send :include, Gon::Helpers +ActionController::Base.send :include, Gon::GonHelpers \ No newline at end of file