Thursday, May 5, 2011

Routing error when running Rails 3 application server in production mode

I was developing a Rails3 application and I wanted to execute a bunch of JavaScript code only on production server. So, in order to do that in my view I added these lines:

<%- if RAILS_ENV == "production" -%>
      -- my JavaScript code --
<% end %>

Now, I wanted to test the code before deploying it on production. So, I needed to start the Rails server in production mode. To start a Rails3 application server in production mode, I passed '-e production' parameter as:
rails s -e production

But when I started browsing the application, all the stylesheets, images were gone and was getting Routing errors similar to the one given below:
Started GET "/javascripts/jquery.js?1303373839" for at Thu May 05 19:55:09 +0530 2011

ActionController::RoutingError (No route matches "/javascripts/jquery.js"):

Reason was - Rails defaults not serve static assets in production, so to fix Routing Errors, I changed

config.serve_static_assets = false
line in 'config/environments/production.rb' to
config.serve_static_assets = true

And restarted the server in production mode. It solved the Routing issue.


  1. Got the same in development mode. Any ideas?

  2. Hi Nisse,

    Can you post the error message? Have you included stylesheet, javascript and given right path for images?


  3. Thanks very helpful and to the point article!

  4. My very first comment on your site. I have been reading your blog for a while and thought I would completely pop in and drop a friendly note. It is great stuff indeed, continuation with ror application development.

    hire ruby on rails developer