Thursday, July 31, 2008

TextMate discoveries

Option+Apple+o = Overwrite mode

Thursday, July 17, 2008

Wednesday, June 18, 2008

Migrating in a production environment

rake db:migrate RAILS_ENV=production
or
rake db:migrate RAILS_ENV="production"

Sunday, June 8, 2008

Add localhost.localdomain to local DNS (or hosts file)

  1. Goto Start > Run
  2. Type in "system32" (without the quotations)
  3. Goto the folder called "drivers"
  4. Goto the folder called "etc"

The hosts file should be in there. Just open it up with notepad or something and add in 127.0.0.1 localhost.localdomain

Links:

http://mu.wordpress.org/forums/topic.php?id=3152

Thursday, May 8, 2008

Padding numbers

If you want output as 123.90:
sprintf("%0.2f","123.9")

Tuesday, May 6, 2008

File.new

File.new(file_name).close won't do what I intend to do, i.e. create a file. Instead File.new(file_name,'w').close does the trick. The problem is in the first case the second argument defaults to 'r' which means read. Its strange that parameter is defaulted to read only. When we create file we normally mean we are creating it to write something to the file. So it must default to 'w'.

Saturday, May 3, 2008

DangerousAttributeError

I came across this weird sounding exception while creating a record. At first I didn't know what was wrong with my table. After a little probing I figured it was being caused by an attribute called 'frozen' in my table. I was using it to indicate if that record is frozen or not. But it appears Rails uses this keyword internally for the same purpose I was using that attribute for. I had to change this attribute to a different name (I named it 'frosen') for it to work.

This is what Rails api says about the error:
Raised when attribute has a name reserved by ActiveRecord (when attribute has name of one of ActiveRecord instance methods).

http://api.rubyonrails.com/classes/ActiveRecord/DangerousAttributeError.html