You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Any script using jquery will fail, I think it would be expected to work with the included Coffeescript "compiler", as we usually use:
$ ->
define behavior here...
And this will not work, at least on Windows. I detected it using the Firefox debugger showing '$ is not defined', this is jquery not present.
I solved it:
Install gem jquery-rails if not installed.
Modify the application Gemfile, adding:
gem 'jquery-rails'
Adding to assets/javascript/application.js these lines:
//= require jquery3
//= require jquery_ujs
Just before the //= require rails-ujs.
Now all the coffeescripts work fine.
I think these 3 points should be added to the rails application generator by default.
The text was updated successfully, but these errors were encountered:
Ops. Then it is confusing. Following the tutorials of the Unobtrusive JavaScript you get this error, and it should work out-of-the-box.
IMHO the correct behavior would be the opposite, include it so the coffeescripts would work by default, and then if programmer do not want it, simply remove.
But removing JQuery you get the behavior of things not working OOTB, and I think that is as Rails was intended to be.
Steps to reproduce
Create a new project and create any coffeescript.
Expected behavior
The script using jquery should work.
Actual behavior
Javascript error: $ is not defined.
System configuration
Rails version:
5.1.2
Ruby version:
2.3.3
Any script using jquery will fail, I think it would be expected to work with the included Coffeescript "compiler", as we usually use:
$ ->
define behavior here...
And this will not work, at least on Windows. I detected it using the Firefox debugger showing '$ is not defined', this is jquery not present.
I solved it:
gem 'jquery-rails'
//= require jquery3
//= require jquery_ujs
Just before the //= require rails-ujs.
Now all the coffeescripts work fine.
I think these 3 points should be added to the rails application generator by default.
The text was updated successfully, but these errors were encountered: