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.
Related
After following this tutorial, I tried was able to set up a rails application on an ec2 Ubuntu instance, running nginx web server and puma app server, deployed with capistrano 3. However, none of my assets are showing up, and I'm getting routing errors for basic functions of the Devise gem such as logging out. The chrome dev tool console shows 404 errors for the compiled application.css and application.js files.
I think the assets are there because if I ssh into the instance and go to the folder where my app is, I can see a bunch of files under public/assets. Also, if I check the capistrano logs, I can find the line bundle exec rake assets:precompile, and the status for that is successful. I tried things like going into the production.rb file and changing config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present? to config.serve_static_files = true
but still no assets. I think the biggest suspect is that there is some sort of routing error, because I don't really understand how web servers, app servers, and aws instances interact with each other. Could anyone point me in the right direction on debugging this? If you need to see a specific config file please comment below.
Ok it turns out all I had to do is copy the secrets.yml from the local repo for my app to the shared folder that is in [my_app_name]/shared/config. So my app didn't know where to look for the secret key base.
Although I'm still confused on why not having the secret.yml would prevent assets from served...
I'm learning Ruby on Rails. At the moment I'm just running my site locally with rails server in the OS X Terminal. What changes when a Rails site is run on a production box?
Is the site still started with rails server?
Any differences with how the db is setup?
Note: I'm running Rails 3.
A rails app can be run in production calling rails server -e production, although 99% of the time you'll be serving on something like passenger or thin instead of WEBrick, which means there's a different command to start the server. (thin start -e production for instance)
This is a complicated question, but the best place to start learning about the differences would be to look at the specific environment.rb files. When rails boots up it starts with the environment file that matches the called environment, ie if you start it in development it begins by loading your development.rb file, or if you're in production it will load the production.rb file. The differences in environments are mostly the result of these differences in the various environment config files.
Basically if a Rails 3.1 app is in production mode, then by default it is not going to be compiling assets on the fly, and a lot of caching will be going on that isn't happening in development. Also, when you get error messages they will be logged but not rendered to the user, instead the static error page from your public directory will be used.
To get more insight into this, I would suggest reading the relevant rails guides:
Rails Initialization Guide: http://guides.rubyonrails.org/initialization.html
Rails Configuration Guide: http://guides.rubyonrails.org/configuring.html
There are two contexts you can use the word "production" here. One of them is running the server in production mode. You can do this locally by,
RAILS_ENV=production ./script/server
The configuration for this is picked up from config/environments/production.rb. Try comparing this file with config/environments/development.rb. There are only subtle differences like caching classes. Development mode makes it easier so that it will respond to any changes you make instantly. Plus there are two different databases (by default) will be used namely yourproject_development and yourproject_production if you choose to run your server in either of these modes.
On the other hand, rails deployment to a production box is something different. You will need to pick your server carefully. You may have to deal with a deployment script may be capistrano. You may also need a load balancer such as netgear. The database also may require a deep consideration like size expectation, master/slave clustering etc.,
Note: I have never used Rails 3. This answer is biased towards 2.3.x.
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!
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.
I'm using the latest rails 3 beta. The app works fine in development mode, but when I start the server in production mode via rails server -e production, it seems that the public folder can't be found. I get error messages like:
ActionController::RoutingError (No route matches "/javascripts/jquery.js"):
And similar messages for everything that should be in the public folder.
I've tried this with both mongrel and webrick. I'd appreciate any help.
editing config/environments/production.rb and setting this line:
config.serve_static_assets = true
nginx, unicorn and apache will do this automatically. be sure to change this back to false if you are deploying using these servers.