Sam Selikoff
Sam Selikoff

Reputation: 12694

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.

Upvotes: 5

Views: 1079

Answers (1)

Sam Selikoff
Sam Selikoff

Reputation: 12694

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!

Upvotes: 4

Related Questions