1

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"):
Damien Roche
  • 13,189
  • 18
  • 68
  • 96
  • Do you have the rubyracer gem installed? – weexpectedTHIS Sep 11 '12 at 02:12
  • I didn't, but I just installed and it doesn't work with our without it. Could you explain why that could be the issue? I thought rubyracer was for javascript? I've updated with exact error message I receive. – Damien Roche Sep 11 '12 at 02:16
  • How does apache fit in? Are you trying to use apache as a reverse proxy? Do you have a ruby module such as phusion passenger installed? What do you get for the contents of `public/assets`? – patrickmcgraw Sep 11 '12 at 02:31
  • @patrickmcgraw The assets are precompiled and are being served if I use apache to listen on port 80. I'm using apache to serve static assets. public/assets contains all assets for my app including application.css. As I say, it resolves fine on 80, but when I use same port as rails server, rails insists on serving the static even after I've specifically told it not to (config.serve_static_assets = false). – Damien Roche Sep 11 '12 at 02:34

1 Answers1

5

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

Community
  • 1
  • 1
Christian
  • 1,258
  • 10
  • 11
  • Thanks. I'll have a read and try to understand the setup more. – Damien Roche Sep 11 '12 at 02:39
  • I'll accept this answer as, although I've not figured it out yet, I understand it is due to my own negligence and the clue is somewhere in your answer. In the mean time, I did somehow install and configure unicorn and nginx :) – Damien Roche Sep 11 '12 at 04:24
  • That's great. Unicorn is a good choice! Sorry if I was not clear enough. Let me know if I can give you some more help. – Christian Sep 11 '12 at 11:48