Archive for November, 2007

Ruby on Rails: NoMethodError in Controller#action – Undefined method ‘each’

Tuesday, November 27th, 2007

I set an instance variable by running the following query:

@some_list = Model.find_by_column_name(nil)

I tried to interate the content of @some_list and received the following error:

NoMethodError in Controller#action

Showing app/views/model/list.rhtml where line [line number] raised:

undefined method `each’ for #…

Apparently, I just need to add “_all_” in the query:

@some_list = Model.find_all_by_column_name(nil)

Easy solution, eh? :)

Update: I found the solution after I looked at the back-end SQL query.

Task Load (0.000354) SELECT * FROM table WHERE [some condition] LIMIT 1

After I added “_all_” in the statement, I finally get the right query.

Task Load (0.000332) SELECT * FROM table WHERE [some condition]

Rails Database Convention

Thursday, November 22nd, 2007

I finally start to create my own Rails application and it is not easy to remember all the RoR conventions.

Raaum.org has a very good database conventions that RoR (*cough*) “recommends.”

Obviously, I use Locomotive for my Rails development. :)

Thank you, Ryan! :)