I am developing a rails app with this method in it:
# PUT /newsletters/1;send
newsletter = Newsletter.find_by_id_and_sent(params[:id], false)
users = User.find(:all)
users.each do |user| #evaluates to nil.each - debug
I get an error saying that users.each do |user| evaluates to nil.each,
and that I probably expected an Array object there. This is true, I did
expect an Array object. Thing is, now I've tried to debug the code with
both debugger and raise to_yaml, and both times the users variable
evaluates to a perfect Array of 3 Users, exactly in correspondence with
the DB! I have also tried to debug the user variable and it evaluates to
a User with id 1, meaning the iterator fetches that user successfully
from the Array.
Yet after the first iteration, I get an error / crash.
I have tried to change users to @users, with the exact same result.
Debugging shows an Array of 3 user objects. The app crashes.
What is going on here?
Thanks in advance, Vahagn