Category Archives: rails

rails template

Usage $ rails app_name -m ./ahabman_template.rb

Posted in rails | Leave a comment

ruby on rails – has and belongs to many view plugin

So I’ll never have to write another has_and_belongs_to_many view again, here’s a plugin that dynamically makes 2 <ul> lists which you drag and drop both ways to manage the association. From the readme: Assumming you have an @project var and you want to associate people with it. “shared/m2m”, :locals => { :thing => @project, […]

Posted in rails | Leave a comment

You can’t use class variables in rails.

You can’t use class variables in rails. Unless you’d like to develop in production mode (specifically with config.cache_classes = true). In development mode all classes are reloaded on each request, which clears all class variables. I had the perfect place to use them – while running a mass synchronization, and needing to store the timestamp […]

Posted in rails | Leave a comment

ruby csv to structured hash

I had a csv like this: object color flavor shape apple red sweet round banana yellow sweet long lemon yellow sour round and I wanted a ruby hash structured like this: So I wrote this, which does the job:

Also posted in ruby | 1 Comment

Ruby conversion module

This is a ruby module useful for conversions dealing with length, weight, torque.

Also posted in ruby | Leave a comment

Rails redirect_to :back in Internet Explorer

Today I realized that the rails command redirect_to :back does not work in Internet Explorer because redirect_to :back depends on the HTTP_REFERER http header, which IE does not send. I was capturing an onclick event with jQuery and was able to sending along the current URL as a query string, which provided an easy way […]

Posted in rails | 1 Comment

Rails background process – simple, fast, easy.

My situation was this – Rails 2.0 app running on slicehost (ubuntu 8.04) in passenger mod_rails The goal was Dynamic PDF generation for a product catalog ( > 100 pages) This event had to be triggered from within the rails request / response cycle, but run outside of it I needed the simplest, fastest, more […]

Posted in rails | Leave a comment

mod_rails set RAILS_ENV variable to QA, Staging, or Production

I’m using mod_rails with capistrano and multi-stage (qa, staging, production), and wrote this workaround so that the RAILS_ENV could be set correctly in each stage. Mod_rails sets RAILS_ENV once in the global server conf file, but I needed it set once for each environment: qa, staging, and production. I tried setting ENV[‘RAILS_ENV] in each file […]

Posted in rails | Tagged | 3 Comments