Question

I have a strange behavior with my engine gem https://github.com/antpaw/bhf on the production environment. The bhf/application.js and bhf/application.css is compiled the way you would expect it and also linked the right way in the template. But none of the assets/bhf/image files are compiled and can be found in shared/assets/bhf/ on production server, unless i change
config.serve_static_assets = false
to true in production.rb?

How bad is it to use this setting? And is there a way for my engine to work out-of-the-box?

Was it helpful?

Solution

Per your gemspec https://github.com/antpaw/bhf/blob/master/bhf.gemspec

It has a dependency on rails v4 s.add_dependency(%q<rails>, [">= 4.0.0"])

I suspect its related to asset digest. Where the assets are getting compiled as expected with digest but are referred from respective CSS without digest.

Its a possible issue with sprockets-rails discussed here issue#49

non-stupid-digest-assets - not so good but preferred solution

It will copy non-digested assets to /public

OTHER TIPS

Are you using Webrick in production? If so, you will need to set config.serve_static_assets = true since it's no good at serving static assets. Other Ruby 'app servers' aren't also ideal for serving static assets so you'll need to have Rails do that for the meantime. It's not an ideal set-up though since page caching won't work and all requests will hit your app.

Once you use a proper server for serving static assets like Nginx or Apache, you will need to set it to config.serve_static_assets = false so that Rails will leave it to Nginx/Apache to handle serving static assets. That way, not all requests will have to hit your Rails app since caching will work.

Since you're building a Rails engine, you don't need to worry about that since that is the responsibility of the one who is deploying the Rails app. You won't have control over their config.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top