gazay/gon

Problem gon navigate with turbolinks

igortice opened this issue · 2 comments

peek 18-12-2018 10-46

rails version: 5.2.2
ruby version: 2.5.3
gon version: 6.2.1

I have two actions:

class IndexController < ApplicationController
  def index
    @your_int = 123
    @your_array = [1,2]
    @your_hash = {'a' => 1, 'b' => 2}
    gon.your_int = @your_int
    gon.your_other_int = 345 + gon.your_int
    gon.your_array = @your_array
    gon.your_array << gon.your_int
    gon.your_hash = @your_hash
  end

  def about
  end
end

in my header i put gon:

%meta{content: 'text/html; charset=UTF-8', 'http-equiv': 'Content-Type'}

%meta{content: 'no-cache', name: 'turbolinks-cache-control'}

= Gon::Base.render_data

%title Testes

-#= favicon_link_tag

= csrf_meta_tags

= csp_meta_tag

= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track': 'reload'

= javascript_include_tag 'application', 'data-turbolinks-track': 'reload'

in browser colose on page index i write gon and returns this:

gon
{your_int: 123, your_other_int: 468, your_array: Array(3), your_hash: {…}}

i navigate with turbolinks to page about and i write gon from console and return this:

gon
{}

so i back to index with tuborlinks and i write in console gon and the return not put the value, but an empty object

gon
{}
baran commented

Hi,

I'm having the same problem. In addition, the existing problem seems to have never been assigned. It seems that the values have been passed to the variables in the first run.

rails version: 5.2.2
ruby version: 2.5.3
gon version: 6.2.1

screen shot 2018-12-24 at 13 00 06

windy commented

Hi, I found this problem, and resolved by this way:

Change <%= Gon::Base.render_data %> from head to body.