igor-alexandrov / wiselinks

If Turbolinks are not enough for you. Wiselinks makes your application work faster.
MIT License
726 stars 93 forks source link

gon variables not inserted into javascript #89

Open jersingh opened 9 years ago

jersingh commented 9 years ago

Not sure if this is a gon issue or a wiselinks issue, but I will start here: I'm using the gon gem to pass data from my controller into javascript. This is my controller:

def index
  @users = User.all
  gon.my_var = 'data'
end

After the corresponding page loads, if I break inside page:done in application.js, I don't see gon variable. If I do a normal browser refresh and bypass wiselinks, the variable does make it into javascript.

Is this just an incompatability between the two gems?

Thanks, Joe

jersingh commented 9 years ago

I solved this by placing the <%= include_gon %> tag inside each view action (in my case, the index view) instead of placing it after the <%= javascript_include_tag 'application' %> tag and that fixed the issue.

Perhaps is has something to with the fact that I don't use the body tab for replacement? I wrap the yield inside a div as shown and replace using "yield-content":

<body>
<div id="wrapper">
  <header>
    <%= render 'layouts/navigation' %>
  </header>
  <main role="main">
    <div id="yield-content">
      <%= yield %>
    </div>
  </main>
</div>
</body>

Anyone using the gon gem with wiselinks? Maybe a better solution exists than what I have done which seems really hacky.