On 5 December 2011 02:11, Dave Aronson
<[email protected]> wrote:
> On Fri, Dec 2, 2011 at 21:56, Moises Luza Ramirez <[email protected]> 
> wrote:
>
>> ActionView::Template::Error (undefined method `each' for #<Payment:
>> 0x10a3039e0>):
>>   9:          </tr>
>>   10:         </thead>
>>   11:         <tbody>
>>   12:         <% for payment in @payments do %>
>
> It's saying that @payments is a Payment, not an array of them.  This
> means that your statement:
>
>>   @payments =
>> Payment.joins(:application_form).where('application_forms.status'
>> =>'pending')
>
> is returning a single Payment object.  I don't know why it's doing
> that -- maybe it's correct behavior in the case of one result, but it
> seems to me a one-element array would be "least surprising".  As a
> workaround you could try immediately after that:
>
>  @payments = [@payments] if Payment === @payments
>
> Let us know how that works for you.
>
> Alternately, are you absolutely sure that nothing else is modifying
> @payments?  Since you have both singular and plural versions, it's
> quite plausible that you added an s on some line where you didn't mean
> to.  Try searching the controller, view, and partials for @payments
> and objectively inspecting each occurrence.

Also you can use ruby-debug to break into your code (after @payments =
... for example) and inspect the data to check it is correct.
Similarly you can break into the code in the view to check it is still
ok.  Have a look at the Rails Guide on debugging to see how to do
that, and also to see some other debugging techniques.

Colin

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to