Rails 4 Mountable Engine, couldn’t find file ‘jquery’

I’m creating a rails mountable engine plugin which uses the gem “jquery-rails”. I added this code in .gemspec file

s.add_dependency "jquery-rails", "~> 3.0.1"

and run bundle install, bundle update. (BTW is this adding necessary? Since rails mountable engine already added “rails 4.0.1” which in turn required “jquery-rails 3.0.4” as its dependency from the start?).

In app/assets/javascript/mountable_engine_name/application.js

//= require jquery
//= require jquery-ujs
//= require_tree .

But when I run the server on test/dummy/ and access any template which uses the tag <%= javascript_include_tag "mountable_engine_name/application" %> it’s showing the error “couldn’t find file ‘jquery'”.

I tried creating a brand new mountable engine plugin but it happens the same.

Did I do something wrong?

PS. Sorry for my English.

UPDATE
Actually it happens on all every manifest file which require jquery and jquery-ujs both in app/assets/javascript/ and test/dummy/app/assets/javascript/ .

Answer

I know the original question was asked a few months ago, but I ran into the same problem while working through the Rails engine tutorial, so I’m posting in case this helps others…

I found that I needed to update four files:

1.) add a dependency to your .gemspec file

    #file: <your engine name>.gemspec

    s.add_dependency "jquery-rails", "~> 3.1.1"

2.) update your engine application.js file:

    #file: <your engine name>/app/assets/javascripts/blorgh/application.js

    ...
    //= require jquery                                                                                                                         
    //= require jquery_ujs                                                                                                                     
    //= require_tree .

3.) update your parent app application.js file:

    #file: <your engine name>/test/dummy/app/assets/javascripts/application.js

    ...
    //= require jquery                                                                                                                         
    //= require jquery_ujs                                                                                                                     
    //= require_tree .

4.) per this SO thread, you need to add a require to your engine.rb file:

    #file: lib/<your engine name>/engine.rb

    module <your engine name>
      class Engine < ::Rails::Engine
        require 'jquery-rails'
        isolate_namespace Blorgh
      end
    end

peace.

Source: stackoverflow
The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .