Here how I use gem gon with rails-4.2.0. Nothing special really:
# Gemfile.lock where rails binded to version 4.2.0
gon (5.2.3)
actionpack (>= 2.3.0)
json
multi_json
request_store (>= 1.0.5)
....
PATH
remote: engines/mobile_api
specs:
mobile_api (0.1)
itunes-receipt
rails (~> 4.2.0)
# Gemfile
source 'http://rubygems.org'
gem 'rails', '4.2.0'
gem 'gon'
# layout main.html.slim
doctype html
html
head
meta charset="utf-8"
= include_gon
# main_controller.rb (In the controller)
class MainController < ApplicationBaseController
before_action :start_marketing_split_test
layout 'main'
# ... actions here
def start_marketing_split_test
split_test_name = 'ab_test_1'
alternatives_loader =
Marketing::AB::AlternativesLoader.new(split_test_name)
alternative = ab_test(split_test_name,
alternatives_loader.alternatives)
gon.push({"#{split_test_name}" => JSON.parse(alternative)})
end
============================
But if you need solution without gon you can pass variables right in you backend templates:
For example:
# layouts/application.html.slim
doctype html
html
head
meta charset="utf-8"
title
body
javascript:
window.app_options = {
'flash_alert': "#{raw(flash[:alert])}",
'flash_warning': "#{raw(flash[:warning])}",
'flash_notice': "#{raw(flash[:notice])}",
'current_user_id': "#{current_user.try(:id)}",
'current_user_phone': "#{current_user.try(:phone)}"
};
gonis working with rails 4.2. I have used it in one of my rails-4.2.1 projects