Posts Tagged tips
- Extending the timeout for Rails processes through Passenger on Nginx - August 5th, 2009
I recently had to allow for a long running reporting task in a Rails app which is running under Passenger (mod_rails) on Nginx
The default setting is 60 seconds and setting send_timeout to 300 in the Nginx config wasn’t working.
After much searching, I found the answer. Edit
/ext/nginx/Conguration.c and change the lines:
ngx_conf_merge_msec_value(conf->upstream.send_timeout, prev->upstream.send_timeout, 60000);
ngx_conf_merge_msec_value(conf->upstream.read_timeout, prev->upstream.read_timeout, 60000);
to (for [...] - Rails plugin that provides rake tasks for identifying missing specs - June 18th, 2009
I have a bad habbit of generating my views while specing the controller and then never generating a view spec.
I wrote a rake task to tell me which views have no specs, kind of like a rcov for views.
I then realised that it could be useful to find all files with missing specs so now [...] - How to select an array of values in Rails - June 15th, 2009
I recently wanted to get a list of IDs from rails, but wanted them in an array.
First try is to use :select => ‘id’ in:
Model.find(:all, :select => ‘id’)
but that creates a model for each id
In order to get an array of values, you can use select_values:
Model.connection.select_values(’select id from models’)
This is great, but what if you [...] - Accessing the Rails logger inside of library files - June 10th, 2009
A quick tip, if you’re developing a library which lives inside of RAILS_ROOT/lib, you can use the Rails logger via DEFAULT_RAILS_LOGGER
class MyLib
def my_method
RAILS_DEFAULT_LOGGER.info "my log message" if RAILS_DEFAULT_LOGGER
end
end
I added if RAILS_DEFAULT_LOGGER so that it doesn’t trip up if used outside of RAILS - Download a large amount of data in CSV from Rails - June 3rd, 2009
I’ve just had to re-write an export script because the application now needed to be able to download 14000 records in CSV format.
Originally I was reading all the records (with multiple joins) and then creating a csv string and then writing it to the response using send_data.
The original code
This is a simplified version of my [...] - Conditionally include development gems - May 28th, 2009
I was playing with metric_fu and after having to install multiple dependency gems I realised that it was going to be a pain to put the project into production.
The metric_fu instructions suggest using config.gem in your environment file but that will mean that when you push the app to production, you need to install the [...] - How to protect downloads but still have nginx serve the files - January 13th, 2009
I’ve just been working on a project where a number of downloads needed to be restricted to specific users. I needed to authenticate the user and then allow them access to the file. This is not too difficult in rails:
def download
if authenticated?
send_file #{RAILS_ROOT}/downloads/images/myfile.zip’
end
end
The problem with this is that if the file [...] - How to make a custom form builder in Rails - January 6th, 2009
A quick run through creating a custom form builder in rails. This particular form builder will inline error messages into your form labels.

