-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Gaining access to the rails variables inside js file #1684
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
In a standard (non-Webpacker) If you cannot use gon, I guess you have to do it manually and set the variables in the view and access them then in your Javascript. |
Yup, I am not looking at non-webpacker setup but mainly looking at I was hoping that Rails' ujs has something available for direct usage. |
Not sure if that's easily doable unless you extend the Is it not possible to use <div data-attrs="{something: "foo"}" id="foo">
</div> const foo = JSON.parse(document.getElementById('foo').dataset.attrs);
foo.something |
@ytbryan Did that work for you? Can we close this? |
If I may ask, what's really the point of Erb in JS if we can't access Rails variables? |
Uh oh!
There was an error while loading. Please reload this page.
Hi folks,
does anyone know how do I access the rails variables via erb inside a .js file. I am not looking for an alternate solution like using the
gon
rubygem.From #1256, I know I can access the ActionController' helpers using:
How do I print the rails variable (@something) of my index action of Actioncontroller, inside the js.erb?
For instance,
What am I missing here? Appreciate any pointers. Thank you!
The text was updated successfully, but these errors were encountered: