Ruby on Rails: NoMethodError in Controller#action - Undefined method ‘each’
Tuesday, November 27th, 2007I 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]