Arnaud
Arnaud

Reputation: 17797

Rails: assets unavailable in staging environment

I'm trying to setup a staging environment.

I copied the environments/production.rb to create environments/staging.rb.

I tested the staging environment locally and ran

RAILS_ENV=staging rake assets:clean assets:precompile
RAILS_ENV=staging rails s

Assets are properly generated in public/assets, and when I load a page, the links to the assets are correct (eg: /assets/application-e014056a81279320a97c71ed25eb46ab.css)

But the browser can't load them and if I try to open

http://localhost:3000/assets/application-e014056a81279320a97c71ed25eb46ab.css

I get a 404.

Now the strange thing is that it works in production, with:

RAILS_ENV=production rake assets:clean assets:precompile
RAILS_ENV=production rails s

For both environments/staging.rb and environments/production.rb, the config is

config.serve_static_assets = false

config.assets.compile = false

config.assets.digest = true

And in application.rb

Bundler.require(*Rails.groups(assets: %w(development test)))

Do you have any idea where to look ? What else could differentiate the staging environment from the production environment ?

Upvotes: 0

Views: 1206

Answers (1)

Arnaud
Arnaud

Reputation: 17797

So, I had forgotten the role of the 'rails_12factor' gem.

I updated my Gemfile to

gem 'rails_12factor', group: [:staging, :production]

And everything works now.

Upvotes: 3

Related Questions