Comments (11)
Hey! Thanks for response!
Did you try this on new application or just on your app? What logic in your root action?
from gon.
In my app, I actually never go to the root action / "home" page, since the app is meant to run in Qt webkit, and the Qt application makes URL requests to the Rails app like "http://localhost:3000/[email protected]&password=admin" and then the Rails app would typically respond with the proper webpage.
I didn't try on a new application, just on this app.
The error occurs in the webpage when I test the url and in the Qt app. (If it doesn't work in the webpage, then it definitely won't work in the Qt app - I just want to point out the error doesn't have anything to do with Qt)
from gon.
I'm sorry but I can't reproduce this bug on new rails app, and don't know your environment. If you can do some debug or tests - it will be helpful! And of course it will be super if you can do pull request with tests for this case or fix for this bug :)
from gon.
Ah, I found out the issue: I was declaring Gon.global variables in ApplicationController where there was a before_filter:
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :authenticate!
# These are constant variables for clear comparison/code readability across controllers and coffee files.
# So, when a controller action uses Gon to set a variable, the coffeescript can get the same value reliably.
# These are enums, essentially
# these should be what controller sets gon.view to
Gon.global.OTHER_VIEW = 'other'
Gon.global.PROJECTS_SHOW = 'projects/show'
Gon.global.FOLDERS_SHOW = 'folders/show'
What would be the proper place to define these global gon variables?
from gon.
I advice to create some initializer for gon and create global variables there if it's possible (if there no dynamic variables). If not - you should do some singleton method which should check define of global variables and place it before call.
from gon.
Okay, since the variables are static, I should simply put them in config/initializers/mygonfile.rb ? Will it be automatically included?
Thanks!
from gon.
Yes, it should) If all will be ok - please close the issue)
from gon.
Actually the error has to do with setting Gon.global.myvariable anywhere, it seems... when I have it set in an initializer, the error persists. I'm digging around in your code right now, and it all starts here:
gon / lib / gon / helpers.rb
def include_gon(options = {})
if variables_for_request_present?
Gon::Base.render_data(options)
elsif Gon.global.all_variables.present?
Gon.clear
Gon::Base.render_data(options)
elsif options[:init].present?
Gon.clear if Gon.all_variables.present?
Gon::Base.render_data(options)
else
""
end
end
The problem might stem from a misunderstanding of your include_gon method... mine has no arguments, yet Gon.clear is still being called (I suspect b/c I set global variables?)
from gon.
Could you clarify your usage section? https://github.com/gazay/gon#usage
I don't understand namespace or init or camel case...
from gon.
I found bug I think, I'll do new version tomorrow
Thanks!
About usage sections - I thought there are all simple - you pass some option to include gon and it's change you end javascript
from gon.
fixed in 3.0.4
from gon.
Related Issues (20)
- ReferenceError: Can't find variable: gon in Javascript Test Case
- use from engine HOT 2
- Gon variable "undefined" when nested in a format.js statement
- Any thoughts on ways to make gon play nicely with webpacker? HOT 4
- gon.watch not update variable in different browser windows.
- Write to localstorage
- How to use Base64.urlsafe_decode64 for a gon variable.
- json.cache! is not working when using gon.jbuilder HOT 1
- Is there a way to update gon through a remote call (JS)? HOT 1
- How to use CSP `nonce` option with Rails 5.2? HOT 3
- A new version possible? HOT 2
- NoMethodError: undefined method `create' for ActionDispatch::TestRequest:Class with rails 4
- Problem gon navigate with turbolinks HOT 2
- Is there a way to set gon variables with a proc? HOT 1
- Option to print variables one per line HOT 2
- Cannot access Rails view helpers methods when using with JBuilder HOT 1
- test failure with rails 6 - Gon#include_gon outputs correct js with a script string
- undefined variable include_gon HOT 1
- Array attribute types incorrectly rendered with Jbuilder using key_format! option
- Why do my objects only contain ID strings after transmitting via gon? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gon.