我有一个博客引擎并添加到Rails应用程序:
将public
文件夹和文件js添加到引擎:
\公共\ sliderengine \ amazingslider.js
engine.rb
: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
:s.files = Dir [“{app,config,db,lib,public} / ** / *”,“MIT-LICENSE”, “Rakefile”,“README.md”]
index.html.erb
的文件中使用文件j:<script src="sliderengine/amazingslider.js"></script>
结果:运行Rails App时发生错误:
GET http://localhost:3000/blog/sliderengine/amazingslider.js 404 (Not Found)
如何在Rails Engine中使用[public]文件夹?
答案 0 :(得分:1)
您必须将引擎的公用文件夹复制到Rails App的公共/博客文件夹
答案 1 :(得分:-1)
嗯。我是这样做的:
将js放在引擎的assets文件夹中(我把它放在引擎名下):
app/assets/javascripts/blorgh/amazingslider.js
然后在引擎中添加:
#blorg/app/assets/javascripts/blorgh.js
//= require_tree ./blorgh
然后在应用
#application.js
//= require blorgh