I'm working on a Rails engine. 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.
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 run the dummy app within the Rails engine itself, or install the engine inside a separate app on my filesystem via path
:
gem 'my-engine', path: '~/my-engine`
everything works. But once I publish to RubyGems and install in another app via
gem 'my-engine'
the static assets all 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
:
Gem::Specification.new do |s|
..
s.files = Dir["{app,config,db,lib,public}/**/*", "MIT-LICENSE", "Rakefile", "README.rdoc"]
Everything works now!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With