Skip to content
This repository has been archived by the owner on Oct 11, 2019. It is now read-only.

gon variables not inserted into javascript #89

Open
jersingh opened this issue Oct 23, 2014 · 1 comment
Open

gon variables not inserted into javascript #89

jersingh opened this issue Oct 23, 2014 · 1 comment

Comments

@jersingh
Copy link

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
Copy link
Author

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant