Rails 4可挂载引擎,找不到文件"jquery"
我正在创建一个使用宝石"jquery-rails"的可安装在Rails上的引擎插件.我在.gemspec文件
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"
,然后运行bundle install
,bundle update
. (顺便说一句,这种添加是必要的吗?因为可安装在Rails上的引擎已经添加了"rails 4.0.1",而从一开始它就又依赖于"jquery-rails 3.0.4"?).
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?).
在app/assets/javascript/mountable_engine_name/application.js
In app/assets/javascript/mountable_engine_name/application.js
//= require jquery
//= require jquery-ujs
//= require_tree .
但是,当我在test/dummy/上运行服务器并访问使用标签<%= javascript_include_tag "mountable_engine_name/application" %>
的任何模板时,它显示错误找不到文件'jquery'" .
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.
我做错了吗?
PS.对不起我的英语不好.
PS. Sorry for my English.
更新
实际上,它发生在app/assets/javascript/和test/dummy/app/assets/javascript/中所有需要jquery和jquery-ujs的清单文件中.
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/ .
我知道最初的问题是在几个月前提出的,但是我遇到了同样的问题 在Rails引擎教程中遇到问题,所以我发布以防万一 这对其他人有帮助...
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.)向您的.gemspec文件添加依赖项
1.) add a dependency to your .gemspec file
#file: <your engine name>.gemspec
s.add_dependency "jquery-rails", "~> 3.1.1"
2.)更新您的引擎application.js文件:
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.)更新您的父应用程序application.js文件:
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.)按照此 SO线程,您需要在engine.rb文件中添加一个需求:
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
和平.