routing errors while changing into production mode in rails3 - ruby-on-rails

Hey, I hope you can help me. Ive been working in development mode all the time.
Everything seems fine so far. As I started up the production mode all my .css and .js got routing errors and were not visible.
Many thanks!
Started GET "/javascripts/application.js?1293486752" for 127.0.0.1 at Thu Jan 13 23:11:21 +0100 2011
ActionController::RoutingError (No route matches "/javascripts/application.js"):

Rails defaults to not serving static assets in production, as the web server is generally more optimized for those kind of tasks. Most likely this is the problem.
To fix it, you can either set config.serve_static_assets = true in config/environments/production.rb, or configure the web server to do it for you.

Related

Reproduce Asset pipeline bugs that occur in production env, NOT development?

In Rails 3.2.3 app, i encounter an error, similar to the following when deployed to heroku:-
Started GET "/" for 59.xx.xx.xx at 2012-xx-xx xx:xx:xx +0000
Completed 500 Internal Server Error in 62ms
ActionView::Template::Error (style.css isn't precompiled)
so, it turns out: the stylesheet is not getting precompiled for some reason(Yes, I tried assets:precompile).
to fix this, first I have to reproduce this error on my development box, so I may know what is wrong.
Hence, my question is:
how to I reproduce this problem on my machine?
By default, Rails only precompiles application.js and application.css (and all non-JS/CSS assets). If you want it to precompile another file (which you need to do if you use javascript_include_tag, et al. in your layout), you need to add your file to the list of precompiled files.
Open config/environments/production.rb, and there should be a commented out line that begins with config.assets.precompile and an explanation above it. Uncomment this line and change it to:
config.assets.precompile += %w(stylesheets/style.css)
(use the path to style.css if that's not the right directory).
To reproduce this on development, you would have to modify development.rb to have all the same asset settings as production.rb.
[Edit]
As you've found, you can start the built-in Rails server in another environment from the command line--however, this effects everything (class reloading, database connections, email settings, etc.) in addition to the asset pipeline settings, so it can sometimes be deceiving at best (unanticipated side-effects) and dangerous at worst (accidentally sending emails to users). Not that it's not useful, just be careful. ;)
I was able to run production environment on my local dev machine, by simply specifying the environment while starting the server
$ RAILS_ENV=production rails s
=> Booting Thin
=> Rails 3.2.3 application starting in production on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
And was able to reproduce the issue. Didn't knew it was so trivial to switch between development & production environments in rails

Setting up rails - 304 Not Modified

I am newbie trying to learn some code. I am following the tutorial on http://guides.rubyonrails.org/getting_started.html
I am up to the point where I've gotten the welcome aboard message at localhost:3000, the last command I typed into my OSX terminal was "rails server"
The server spit out some info and at the end I got this...
Started GET "/assets/rails.png" for 127.0.0.1 at Fri Jan 27 12:44:36
-0500 2012 Served asset /rails.png - 304 Not Modified (2ms)
Started GET "/assets/rails.png" for 127.0.0.1 at Fri Jan 27 12:48:29
-0500 2012 Served asset /rails.png - 304 Not Modified (0ms)
Now the terminal prompt is not coming up...not sure how to fix or what I should do? Thanks to anyone who can help!
When you type in rails server (or rails s for short) the server starts running in that terminal window. This is a good thing. It means that there was no critical error at start up and rails will proceed by showing you a log of what's happening in your app - what resources it's serving, how long does it take, what views is it rendering, what database queries is it running, etc.
To proceed you can either kill the server by pressing control-C or simply open up a new terminal tab by pressing command-T and work from there and you can always switch to the first tab to look at the log if needed. With rails you usually don't need to restart the server so you can usually just keep it running in a tab in your terminal (an exception to that is when editing stuff in config or your Gemfile).
The server runs until you end it by typing Control+C. What it does is turns your computer in to a web server, and allows you to look at your website by going to http://localhost:3000 (by default this is the webport). There is nothing wrong with your computer or program. The server will show you a log of what it's doing while you navigate your website.
The 304 Not Modified is just telling you that when it went to fetch something, it knows it's done it before and the file was not modified. This is usually true of static assets, like images.

Preventing broken images hitting Rails in development

Anyone know of a simple way to prevent broken images hitting Rails in development?
Sometimes I need to load the production database to debug a specific problem, and the broken images add noise to the logs and slows down Rails.
I'm using pow and am proxying https requests through nginx (on Mac OS X Lion).
[Update]
After upgrading to rails 3.1.3 and adding config.serve_static_assets = false to development.rb, the problem still exists.
Here's an example from the logs:
Started GET "/system/template_pics/images/000/000/043/original-254f3340aa9285267db373d8f479144e-1327358518/home6.jpeg" for 127.0.0.1 at Mon Feb 27 14:42:34 +1100 2012
ActionController::RoutingError (No route matches [GET] "/system/template_pics/images/000/000/043/original-254f3340aa9285267db373d8f479144e-1327358518/home6.jpeg"):
Set rails to not serve static assets in config/development.rb:
config.serve_static_assets = false
Nginx should be setup to serve static assets itself, and any that don't exist won't be server by Rails.
I have a script that deals with updating the development database with a MySQL dump from production, and in it I make sure to zero out the Paperclip fields so that the regular missing.png is loaded on dev and there's no clutter in the logs. So for your template pics, you'd have something like:
update template_pics SET image_file_name=NULL, image_content_type=NULL, image_file_size=NULL, image_updated_at=NULL;
Make sure you have the style variants for your missing.png on development for this to be thorough.

How can I test error pages in rails development environment?

I want to design my 404 page in my Rails 3.0.7 app.
If I request a non existing page I get the development output
Routing Error
No route matches "/foo"
I tried the following answers in:
How to test 500.html in rails development env?
application_controller:
def local_request?
false
end
development.rb:
config.consider_all_requests_local = false
development.rb:
config.action_view.debug_rjs = false
and I also started my app with:
RAILS_ENV=production rails s
RAILS_ENV=production passenger start
None of it worked.I love how rails makes complicated tasks very simple. But it's really frustrating how really simple things turn out tu be overwhelmingly difficult, impossible to debug and you end up hacking on remote servers to work around it..
Has anyone had this problem before?
If your error pages are static you can simply go to http://localhost:3000/404.html, http://localhost:3000/500.html, etc.
Best idea I've come up with so far is to run the server in production mode locally.
rails s -e production
cheers.

rails 3.1 ActionController::RoutingError (No route matches [GET] "/assets/rails.png"):

Standard new rails app has issue showing the rails.png
ActionController::RoutingError (No route matches [GET] "/assets/rails.png"):
I have tried moving the .png file around to various places in assets and assets/images and also the older place 'public' or 'public/images' and changing the page but nothing has helped. Please answer if you have seen and resolved this. I have tried about 20 different combo's myself.
Version:
'rails', '3.1.0.rc4'
I just had a problem throwing a similar error. In my case I was starting the rails server in production mode in Mac OSX using the standard WEBrick. It threw this error because of the line:
config.serve_static_assets = false
in config/environments/production.rb.
That is set because on most production machines the web server itself will handle this.
It looks like you were having a different problem, but I'll post this here for others that run into this error.
It must have been an rc4 issue as the final release didn't have this issue.
11/27/11 - I now wonder if this was just due to the asset pipeline that was introduced in rails 3.1, requiring the rake assets:precompile command (compiles and copies images, css and js from app/assets to public/.
If anyone finds that to be the case, please add a comment!

Resources