Skip to content

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

Closed
@Dark-Schneider-666

Description

@Dark-Schneider-666

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions