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:
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 127.0.0.1 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 = true
And restarted the server in production mode. It solved the Routing issue.
<%- 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 127.0.0.1 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' toconfig.serve_static_assets = true
And restarted the server in production mode. It solved the Routing issue.
Got the same in development mode. Any ideas?
ReplyDeleteHi Nisse,
ReplyDeleteCan you post the error message? Have you included stylesheet, javascript and given right path for images?
Thanks
Ritesh
Thanks very helpful and to the point article!
ReplyDeleteThanks, It's working fine.
ReplyDeleteMy 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.
ReplyDeletehire ruby on rails developer