简体   繁体   English

Rails引擎的静态资产未在主机应用程序中提供

[英]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.

相关问题 Rails 3.1 + Heroku Cedar - 未提供静态图像资源 - Rails 3.1 + Heroku Cedar - Static image assets are not being served 即使设置config.serve_static_assets = true,也无法提供Rails 4静态资产 - rails 4 static assets not being served even after setting config.serve_static_assets = true 带有Rails的Google App Engine,静态资产不起作用 - Google App Engine with Rails, Static Assets not working rails - nginx + puma - 静态资产不是由提供的教程链接中的nginx提供的 - rails - nginx + puma - static assets not being served by nginx from the tutorial link provided Rails-如何使用Heroku在S3上托管静态资产 - Rails - How to host static assets on S3 with Heroku 引擎在 Rails 3.1 中的资产 - Engine's assets with Rails 3.1 为什么 Google App Engine Standard 上不提供预编译资产? - Why aren't precompiled assets served on Google App Engine Standard? 不提供Rails Cloudfront资产 - Rails Cloudfront assets not served 从静态站点热链接到我的Rails 4应用程序的资产 - Hotlinking to my Rails 4 app's assets from a static site 具有相同模型名称的主机应用程序和引擎,使用主机应用程序的部分,导轨从引擎内部渲染主机应用程序的模型 - Host app and engine with same model name, rendering host app's model from inside engine using host app's partial, rails
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM