Skip to content
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

JQuery not included in projects (at least on Windows) #30010

Closed
Dark-Schneider-666 opened this issue Jul 31, 2017 · 3 comments
Closed

JQuery not included in projects (at least on Windows) #30010

Dark-Schneider-666 opened this issue Jul 31, 2017 · 3 comments

Comments

@Dark-Schneider-666
Copy link

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:

  1. Install gem jquery-rails if not installed.
  2. Modify the application Gemfile, adding:
    gem 'jquery-rails'
  3. 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.

@redtachyons
Copy link

redtachyons commented Jul 31, 2017

This is an expected behavior, See #25208

@Dark-Schneider-666
Copy link
Author

Dark-Schneider-666 commented Jul 31, 2017

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.

@guilleiguaran
Copy link
Member

You don't need JQuery to use CoffeeScript and $ have been always the JQuery object, not part of CoffeeScript language.

Following the tutorials of the Unobtrusive JavaScript you get this error

Those tutorials should be updated to reflect the fact that JQuery isn't included anymore in default stack.

Closing this issue since as @redtachyons said, this is totally expected now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants