-
-
Notifications
You must be signed in to change notification settings - Fork 95
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
Can't execute Rails Code in js.erb files #137
Comments
Have you got https://www.npmjs.com/package/rails-erb-loader package installed? This is needed to process erb files but don't think it's included by default. If the package is installed and you're still facing issues, please provide a reproduction repo so we can take a closer look |
Labeling as a question until we determine if really a bug. |
I have created a blank project and everything worked fine. I'm providing you the repo i'm currently working on directly: https://github.com/muehling/CoMapEd/tree/Update_rails In app/views/concept_maps/edit.html.erb i want to load the test.js.erb When you start the server you should be able to get to the edit view by typing in 'abc' if you previously seeded the postgres db. I hope you can get that running. if not please tell me so. and sorry i couldn't provide a simpler repo but the problem seems to be somewhere in this repo. Maybe the problem is even that i upgraded from rails 5 to 7 and have some dead code left.. Thank you very much in advance! |
Hey @Windh0wl I think I've got this working. Looks like spring gem is causing the issue here usabilityhub/rails-erb-loader#63 To try and get this working do the following:
After this, start the server again and it should be now working. Not sure what's the actual cause behind the scenes but I recommend reading through the issue linked above for some insights. Especially usabilityhub/rails-erb-loader#63 (comment) |
@justin808 Separately might need to implement https://github.com/usabilityhub/rails-erb-loader#spring (i.e. adding |
Nice. I get it to work now with a two liner .js.erb but not yet with my /app/views/concept_maps/edit.html.erb .. Is there some js syntax i may not use with .erb ? |
@Windh0wl Hard to say, have you got comments in the file? Those are one of the things that might cause issues here Ruby comments are prefixed with the hash, whereas JS ones are Essentially, what the
You should be able to test your file with something like:
The command above will succeed if your |
awesome. that helped a ton. i can run simple ruby code now. would you happen to know how i can run |
One of the following should work: |
Ok. so this is my setup:
That is working just fine for me. But i expected it to work with just
That just returned "missing locale for en.action_new_node" So it seems the scope is messed up somehow. |
I think that's because scoping the key by partial is the Railsy helper thing rather than You should be able to use just Further to that, just to make sure you are not getting confused. Files like https://github.com/muehling/CoMapEd/blob/Update_rails/app/views/concept_maps/import.js.erb should be processed as app views. Webpack won't touch any of those. It's only stuff that you define in javascript land (in your case |
I am trying to get js.erb files to work with shakapacker. But so far i had no luck. As far as i know there is no installer for erb (bundle exec webpacker:install:erb) anymore like in previous webpacker versions, so this should be supported out of the box, am i correct?
what could i be doing wrong here?
Currently i have the stock webpack.config.js
This is my output:
Ruby version: 2.7
Rails version: 7.0.2
Shakapacker version: 6.3
The text was updated successfully, but these errors were encountered: