Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails engine's static assets not being served in host app

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.

like image 809
Sam Selikoff Avatar asked Sep 28 '22 22:09

Sam Selikoff


1 Answers

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!

like image 71
Sam Selikoff Avatar answered Oct 03 '22 09:10

Sam Selikoff