[英]Rails engine's static assets not being served in host app
I'm working on a Rails engine. 我正在研究Rails引擎。 The engine includes some static JS/CSS in its
public
folder, and I want these assets to be merged into and served by the host application. 该引擎在其
public
文件夹中包含一些静态JS / CSS,我希望这些资产可以合并到宿主应用程序中并由其提供服务。
I added this to my engine.rb
file: 我把它添加到我的
engine.rb
文件中:
initializer "static assets" do |app|
app.middleware.insert_before(::ActionDispatch::Static, ::ActionDispatch::Static, "#{root}/public")
end
Interestingly, when I run the dummy app within the Rails engine itself, or install the engine inside a separate app on my filesystem via path
: 有趣的是,当我在Rails引擎本身内运行虚拟应用程序时, 或者通过
path
将引擎安装在我的文件系统上的单独应用程序中:
gem 'my-engine', path: '~/my-engine`
everything works. 一切正常。 But once I publish to RubyGems and install in another app via
但是,一旦我发布到RubyGems并通过其他应用程序安装
gem 'my-engine'
the static assets all 404. 静态资产全部404。
Any ideas on how to diagnose? 关于如何诊断的任何想法? Is there anything else I need to do within the host app to ensure the static assets are getting pulled in + being served?
在主机应用程序中还有什么我需要做的,以确保静态资产被拉入+服务吗? It's not a production environment thing, because it doesn't even work in development.
它不是生产环境的东西,因为它甚至不能用于开发。
I forgot to public
to the files config option in my .gemspec
: 我忘了
public
我的.gemspec
文件配置选项:
Gem::Specification.new do |s|
..
s.files = Dir["{app,config,db,lib,public}/**/*", "MIT-LICENSE", "Rakefile", "README.rdoc"]
Everything works now! 现在一切正常!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.