Forum: Ruby on Rails undefined method `each' "ERROR" when using AJAX

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
2c49cd424ddb3b3c9cef6ef7f45c8534?d=identicon&s=25 Sam Ginko (ginkod)
on 2009-01-22 18:09
I'm trying to update a set of comments in my app. I'm trying to use ajax
to do so and I'm running into problems. I'm getting the error below

undefined method `each' for #<Ratecomment:0x267ac80>
Extracted source (around line #2):

1: <table width="450" border="0" cellpadding="0" cellspacing="1" >
2:   <% @comments.each do |comment|%>
3:   <tr>
4:     <td>
5:       <div style="padding-bottom:10px;">

Hope someone can help.

######### controller code


  def rate_new

    @furni = Furni.find(params[:id])
    @comments = Ratecomment.new(params[:ratecomment])
    if @comments.save
      Rating.delete_all(["rateable_type = 'Furni' AND rateable_id = ?",
@furnii])
      @furni.add_rating Rating.new(:rating =>
params[:ratecomment]["rating"])
      @comments.save!
    else
      flash[:notice] = 'Comment field can not be empty!'
    end

  end

######### view code
      <div id="rate_div">
    <%= render(:partial => "rate", :object => @comments) %>
  </div>


######### partial code
<table width="450" border="0" cellpadding="0" cellspacing="1" >
  <% @comments.each do |comment|%>
  <tr>
    <td>
      <div style="padding-bottom:10px;">
        <table width="100%" border="0" cellpadding="0" cellspacing="1" >
        <tr>
        <td>
        <ul class='star-rating'>
            <li class='current-rating' style='width:<%= (comment.rating
* 20).to_i -%>px;'>
                  Currently <%= number_with_precision(comment.rating, 1)
%>/5 Stars.<br><br>
            </li>
          <li>
          <li class='one-star'></li>
            <li class='two-stars'></li>
            <li class='three-stars'></li>
            <li class='four-stars'></li>
            <li class='five-stars'></li>
        </ul>
        </td>
        <td align=right class="txtBlackSmall"><font
class="txtGraySmall"><i>date posted:</i></font> <%=
comment.created_at.localtime %></td>
        </tr>
        </table>

      </div>
      <div style="padding-bottom:10px; border-style:solid;
border-bottom-width:1px; border-left-width:0px; border-right-width:0px;
border-top-width:0px; border-color:#cccccc; "><%=comment.content%></div>


    </td>
  </tr>
  <%end%>
</table>


########## content in the rate_new.rjs

page.insert_html :bottom, "rate_div", :partial => "rate", :object =>
@comments
2c49cd424ddb3b3c9cef6ef7f45c8534?d=identicon&s=25 Sam Ginko (ginkod)
on 2009-01-22 18:24
Sam Ginko wrote: CORRECTION ON THE RJS file
the content reads:

page.replace_html "rate_div", :partial => "rate", :object => @comments
This topic is locked and can not be replied to.