Rails不加载可挂载引擎的js
Gemfile
中包含一个可挂载的引擎引擎
gem 'my_engine', :path => 'engines/my_engine'
并安装在主应用程序中
Rails.application.routes.draw do
mount MyEngine::Engine => "/blog", as: 'blog_engine'
end
在app/engines/my_engine/app/assets/javascripts/my_engine/application.js
有
alert('hello');
在app/engines/my_engine/lib/my_engine/engine.rb
添加了
module MyEngine
class Engine < ::Rails::Engine
isolate_namespace MyEngine
# Append engine's migrations to root app's migrations
initializer :append_migrations do |app|
unless app.root.to_s.match root.to_s
config.paths["db/migrate"].expanded.each do |expanded_path|
app.config.paths["db/migrate"] << expanded_path
end
end
end
config.autoload_paths += Dir["#{config.root}/spec/support"]
initializer "my_engine.precompile" do |app|
app.config.assets.paths << Rails.root.join('/engines/my_engine/app/assets/javascripts')
app.config.assets.precompile << "my_engine/application.js"
end
end
end
但是当我重新加载http://localhost:3000/blog
警报消息没有显示出来? 我错过了什么?
您还需要将JavaScript插入到页面中。 您的博客代码中是否有javascript_include_tag
拉动application.js
文件? 它经常被放入其中一种布局中:
<%= javascript_include_tag 'my_engine/application' %>
链接地址: http://www.djcxy.com/p/96329.html