# Undefined method \`each' "ERROR" when using AJAX

**URL:** <https://www.ruby-forum.com/t/undefined-method-each-error-when-using-ajax/158380>\
**Category:** Rails\
**Created:** [January 22, 2009, 6:09pm UTC](https://www.ruby-forum.com/t/undefined-method-each-error-when-using-ajax/158380 "2009-01-22T18:09:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![staypufd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ecd19e/32.png) [@staypufd](https://www.ruby-forum.com/u/staypufd)\
**Post date:** [January 22, 2009, 6:09pm UTC](https://www.ruby-forum.com/t/undefined-method-each-error-when-using-ajax/158380/1 "2009-01-22T18:09:31Z")

</div>

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:

  
2: \<% @comments.each do |comment|%\>  
3:   
4: 

|   
5: 

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

  
\<%= render(:partial =\> “rate”, :object =\> @comments) %\> 

######### partial code

 \<% @comments.each do |comment|%\> \<%end%\>

| 

| 
- Currently \<%= number\_with\_precision(comment.rating, 1) %\>/5 Stars.  
  
- 
- 
- 
- 
- 
- 

 | _date posted:_ \<%= comment.created\_at.localtime %\> |

```
  </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%\>

```
</td>

```

 |

########## content in the rate\_new.rjs

page.insert\_html :bottom, “rate\_div”, :partial =\> “rate”, :object =\>  
@comments

 |

---

<div class="post-metadata">

**Author:** ![staypufd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ecd19e/32.png) [@staypufd](https://www.ruby-forum.com/u/staypufd)\
**Post date:** [January 22, 2009, 6:24pm UTC](https://www.ruby-forum.com/t/undefined-method-each-error-when-using-ajax/158380/2 "2009-01-22T18:24:22Z")

</div>

Sam G. wrote: CORRECTION ON THE RJS file  
the content reads:

page.replace\_html “rate\_div”, :partial =\> “rate”, :object =\> @comments
