1

I am running a rails server in the production environment, and I precompiled my assets, but for some reason the requests are going to the /assets directory instead of /public.

I have the default production.rb file. What could be causing this?

# config/environments/production.rb

config.cache_classes = true
config.consider_all_requests_local       = false
config.action_controller.perform_caching = true
config.serve_static_assets = false
config.assets.compress = true
config.assets.compile = false
config.assets.digest = true
config.force_ssl = true
config.i18n.fallbacks = true
config.active_support.deprecation = :notify

2 Answers 2

1

You can also change:

config.serve_static_assets = true

and then your assets will be served from /public/assets without having to use Apache or Nginx.

For development, just delete the /public/assets directory and then they will be automatically compiled and served from /assets.

1
  • quick solution I was looking for, but I urge people to look into Passenger (see below)
    – AJcodez
    Oct 13, 2012 at 1:43
1

Requests are going to /assets, which are served out of the public directory by the webserver which should sit in front of your Rails app.

Because you've got config.serve_static_assets set to false inside config/environments/production.rb there, Rails isn't going to even try to serve these assets.

I would recommend putting an Apache or Nginx server running Passenger in front of Rails so that Apache or Nginx would serve the assets and proxy requests to your application.

5
  • I don't quite understand... I need 2 servers to make it work in production?
    – AJcodez
    Oct 10, 2012 at 4:24
  • No... you need a server which sits in front of the Rails server and pipes the requests to it. Passenger will spool up an instance of your application automatically and deal with the piping of the requests. The frontend server (apache or nginx) is much faster at serving static assets than anything written in Ruby, that's why it's the preferred method.
    – Ryan Bigg
    Oct 10, 2012 at 4:46
  • Oh I dont really care if its fast, I just want the image to show up! The problem is its looking in the wrong folder for the images. Its in production but looking in assets/ instead of public/assets/
    – AJcodez
    Oct 10, 2012 at 4:48
  • I'll give this Passenger server a try though. Im installing it now
    – AJcodez
    Oct 10, 2012 at 4:49
  • 3
    It's looking in the correct folder :) public files are actually served without their public prefix. This is why you could put index.html inside your public dir, run rails s and go to localhost:3000 and see the contents of that index file locally, even though the request is /, and not /public/
    – Ryan Bigg
    Oct 10, 2012 at 5:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.