Rails static assets are not served in the host application

I am working on a Rails engine. The mechanism includes some static JS / CSS in its public folder, and I want these assets to be combined and served by the host application.

I added this to my engine.rb file:

 initializer "static assets" do |app| app.middleware.insert_before(::ActionDispatch::Static, ::ActionDispatch::Static, "#{root}/public") end 

Interestingly, when I launch a dummy application inside the Rails mechanism itself or install it in a separate application in my file system via path :

 gem 'my-engine', path: '~/my-engine` 

everything works. But as soon as I publish RubyGems and install in another application through

 gem 'my-engine' 

static assets all 404.

Any ideas on how to diagnose? Is there anything else I need to do in the host application to ensure that static assets are pulled into + to be served? This is not a production environment because it does not even work in development.

+5
source share
1 answer

I forgot public in the file configuration option in .gemspec :

 Gem::Specification.new do |s| .. s.files = Dir["{app,config,db,lib,public}/**/*", "MIT-LICENSE", "Rakefile", "README.rdoc"] 

Now everything works!

+4
source

Source: https://habr.com/ru/post/1211835/


All Articles