gon icon indicating copy to clipboard operation
gon copied to clipboard

Not loading in production; uncaught reference error

Open jmzbond opened this issue 10 years ago • 10 comments

Gon works fine in development mode, but in production, it's producing an Uncaught Reference Error: gon is not defined.

I have written <%= include_gon %> in the application layout header before style sheet/ javascript tags.

Any thoughts?

jmzbond avatar Feb 28 '14 22:02 jmzbond

Thank you for issue! Can you please provide full stack trace and example how you use gem?

gazay avatar Mar 13 '14 05:03 gazay

It resolved itself somehow, and I'm not sure how... you can close it!

On Wed, Mar 12, 2014 at 10:42 PM, Alexey Gaziev [email protected]:

Thank you for issue! Can you please provide full stack trace and example how you use gem?

Reply to this email directly or view it on GitHubhttps://github.com/gazay/gon/issues/119#issuecomment-37501966 .

James

*Need to borrow something for occasional use? I can help http://borrows.herokuapp.com. *

jmzbond avatar Mar 14 '14 17:03 jmzbond

I have the same problem on heroku using rails 4: 'uncaught reference error. gon is not defined'

In my gemfile I have: gem "gon", '5.0.4' and I added '<%= include_gon %>' into the head section of my layout file.

works in development though.

javamuc avatar Mar 30 '14 12:03 javamuc

ok I now know what was happening, for those that stumble upon the same problem: include gon like this to make sure that it is available: <%= include_gon(:init => true) %>

and in your javascript, if you access a gon attribute, wrap it in a if to check if it is there, like this: if(gon.attr) console.log(gon.attr)

javamuc avatar Mar 30 '14 13:03 javamuc

@gazay sorry to have you reopened this issue. the problem was how heroku serves all assets as one js. maybe adding a section in the usage might be of help for others.

javamuc avatar Mar 30 '14 13:03 javamuc

Anyway it is and issue and add section to wiki is a good idea) Thank you, I'll do it soon.

gazay avatar Mar 30 '14 13:03 gazay

I'm having this issue today. Gon works 90% of the time in my staging heroku app, but now that I've pushed it to my production Heroku app, it fails 90% of the time, keeping stripe.js from working. I've tried adding 'init: true' (which fails when I try to push it to Heroku), I've tried putting <%= include_gon %> in the body, as well as in the individual key pages, with no success. Has there been a solution to this other than disabling turbolinks?

adsteel avatar Jul 02 '14 21:07 adsteel

+1

richpeck avatar Oct 20 '14 10:10 richpeck

+1 Having this issue as well.

Fourfingerz avatar Jan 22 '15 20:01 Fourfingerz

I never solved this issue. Ultimately, I either passed server side data into html data attributes and retrieved it with the Javascript or retrieved it with Ajax calls directly.

adsteel avatar Jan 22 '15 21:01 adsteel