Thursday, September 23, 2010

Why Rails 3 cannot start the debugger

ruby-debug is installed, but I see

You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug'

This is because I don't have ruby-debug in my Gemfile:

group :development, :test do
gem 'ruby-debug'
end

Wednesday, April 28, 2010

Adding Rails Counter Cache - Two Stage Release

I recently added a counter cache to an existing has_many/belongs_to association. I am using a hosted Rails application (heroku)

I went through all the steps:

1) create a migration adding a table_name_count column to the counting table, and initializing table_name_count to the the proper value

2) add :counter_cache => true to my :belongs_to association

3) make use of .size instead of .count for counting the associations

4) write proper unit tests to verify the counter is updated

It all worked - until deployment. The migration did not fail, but my counter fields remained 0.

Odd, it all worked locally. Must be an issue with my host - NOT.

Here is the skinny:

Specifying :counter_cache => true makes the counter field read only. Updating it does not cause an error, the model can still be saved, and modified? returns true. However, the field does not get saved - it is a transient change.

It wasn't a problem locally, because I had done these in the proper order. With git as my interface to heroku, all these steps were effectively compressed into one.

To fix this, I had to deploy this change in two stages:

A) Migration, initializing the value
B) Model and other code updates.

And it worked.

Wednesday, March 31, 2010

Confirmation Questions

Registration for a web site should be as painless as possible. Some sites don't get this. I recently registered on a web site which required 3 "secret" questions to be answered in case I forgot my password.

This was the most difficult part of registration- Who thinks up these?

What is your most unique characteristic?
  • Subjective? How do I answer this? Why would I answer this when the answer could be stored in plain text
What is your favorite flower?
  • Surprise, don't have one - I'm a guy
What was the last name of your first grade teacher?
  • reasonable question
What is was your first car?
  • reasonable question
What was your most memorable gift as a child?
  • don't remember
Who is your favorite person from history?
  • Is it weird that I don't have one?
Name of a childhood best friend?
  • Was a loner
Name of a college you applied to but did not attend?
  • None
Name of a favorite childhood pet?
  • reasonable
Name the first school you ever attended?
  • Is this asking me to name it? Ok, how about "The Really Big Elementary School"
Name the highest mountain you've been to the top of?
  • Your kidding me... Mount Iliveintheplanes??
What city were you born in?
  • reasonable
What is the last name of the most famous person you've met?
  • Written by someone in California, no doubt.
What is the last name of your childhood doctor?
  • How would I know this? How would I remember this?
What is the name of your favorite novel?
  • Novels are non-fiction - i.e. they are lacking facts, meaning I don't read them
What is your favorite pet's name?
  • Didn't you ask this already? Isn't this subject to change - like when the pet dies? Is this really meant for adults?
What is your youngest sibling's nickname?
  • Didn't have a nickname really
I don't think these people care about the user experience.