I have a blog engine and add to a Rails App:
Add public
folder and file js to engine:
\\public\\sliderengine\\amazingslider.js
engine.rb
of Engine: class Engine < ::Rails::Engine isolate_namespace Blorgh initializer "static assets" do |app| app.middleware.insert_before(::ActionDispatch::Static, ::ActionDispatch::Static, "#{root}/public") end end
.gemspec
of engine: s.files = Dir["{app,config,db,lib,public}/**/*", "MIT-LICENSE", "Rakefile", "README.md"]
index.html.erb
of engine: <script src="sliderengine/amazingslider.js"></script>
Result : occur error when run Rails App:
GET http://localhost:3000/blog/sliderengine/amazingslider.js 404 (Not Found)
How can use [public] folder in Rails Engine?
您必须将引擎的公用文件夹复制到Rails App的public / blog文件夹中
Hm. Here's how I do it:
Put the js in the assets folder of the engine (I put it under the engine name):
app/assets/javascripts/blorgh/amazingslider.js
Then in the engine add:
#blorg/app/assets/javascripts/blorgh.js
//= require_tree ./blorgh
Then in the app
#application.js
//= require blorgh
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.