user419017
user419017

Reputation:

running Rails 3 staging environment locally (404 on all assets)

I'm running my staging server locally using:

RAILS_ENV=staging rails console -p 1337

I have precompiled assets, everything is working fine except I cannot find out how to serve those assets. I have this in my staging.rb:

config.serve_static_assets = false

In my apache vhost, if I listen on 80, I can access my assets:

http://domain.local/assets/application.css

But, if I listen on 1337, the same port as my rails server, then rails spits out a 404. My confusion is, I have already told rails not to serve_static_assets, and so why would it try to serve them?

http://domain.local:1337/assets/application.css

I must be missing something. The site displays fine, just returns 404 on all assets:

ActionController::RoutingError (No route matches [GET] "/assets/application-791b26264f9bbe462a28d08cf9a79582.css"):

Upvotes: 1

Views: 3541

Answers (1)

Christian
Christian

Reputation: 1258

When you access your application through

http://domain.local:1337/

you are not going through Apache.

If you want to run it using only WEBrick (RAILS_ENV=staging rails s -p 1337), then you should set

config.serve_static_assets = true

in your staging.rb . That will make WEBrick serve the precompiled assets when you access your application through

http://domain.local:1337

In order to use the precompiled assets served by Apache you should look into using Apache (or Nginx) in combination with a Ruby module such as Phusion Passenger. Then you will be able to access your app through

http://domain.local

which will make Apache serve your assets and will forward all other requests to the module. You can read more about this here

Upvotes: 5

Related Questions