Hope you have any solution for this

I have a view with two partials:

<!-- LIST -->
<div>
<p id="ppaypend">
<%= render :partial => 'list' %>
</p>
</div>
<!-- FORM -->
<div id="form" style="display: none; ">
<%= render :partial => 'form' %>
</div>

_list.html.erb partial code is here:

<table>
<thead>
<tr>
<th>Service</th>
<th>percentaje</th>
<th>Amount</th>
<th>date</th>
<th>Select</th>
</tr>
</thead>
<tbody>
<% for payment in @payments do %>
<tr>
<td><%= payment.service.description %></td>
<td><%= payment.service.percentage %></td>
<td><%= payment.amount %></td>
<td><%= payment.created_at.to_s(:db) %></td>
<td><%= link_to 'Select',
edit_payment_path(payment), :remote => true %></td>
</tr>
<% end %>
</tbody>
</table>

the idea of the code is when someone select any item in the table the
form appears to show some information and then the user can update and
submit their changes. After the submit the list need to be updated and
I'm doing it with the following code in the update.js.erb file

$("#ppaypend").html("<%= escape_javascript( render :partial =>"list" )
%>");

(when i comment this line everything works but obviously the list does
not show the changes)

in my controller i have this to assure the @payments is created every
request:

class PaymentsController < ApplicationController
before_filter :load

def load
@payments =
Payment.joins(:application_form).where('application_forms.status'
=>'pending')
@payment = Payment.new
end
.....
end

the error i have is:

ActionView::Template::Error (undefined method `each' for #<Payment:
0x10a3039e0>):
9: </tr>
10: </thead>
11: <tbody>
12: <% for payment in @payments do %>
13: <tr>
14: <td><%= payment.service.description
%></td>
15: <td><%= payment.service.percentage
%></td>
app/views/payments/_list.html.erb:12:in
`_app_views_payments__list_html_erb__1381777750_2232227020'
app/views/payments/update.js.erb:3:in
`_app_views_payments_update_js_erb___1521001921_2232244240'
app/controllers/payments_controller.rb:45:in `update'

--
Posted via http://www.ruby-forum.com/.

--
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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

  • Dave Aronson at Dec 5, 2011 at 2:12 am

    On Fri, Dec 2, 2011 at 21:56, Moises Luza Ramirez 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.

    -Dave

    --
    LOOKING FOR WORK! What: Ruby (on/off Rails), Python, other modern languages.
    Where: Northern Virginia, Washington DC (near Orange Line), and remote work.
    See: davearonson.com (main) * codosaur.us (code) * dare2xl.com (excellence).
    Specialization is for insects. (Heinlein) - Have Pun, Will Babble! (Aronson)

    --
    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Colin Law at Dec 5, 2011 at 10:54 am

    On 5 December 2011 02:11, Dave Aronson wrote:
    On Fri, Dec 2, 2011 at 21:56, Moises Luza Ramirez 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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedDec 3, '11 at 2:56a
activeDec 5, '11 at 10:54a
posts3
users3
websiterubyonrails.org
irc#RubyOnRails

People

Translate

site design / logo © 2021 Grokbase