ruby on rails - undefined method `each' for #<Comment:0x007f12ef55d0d0> -


I was working on the Blogger blogger on Rail Blogger:

and I'm at the point where I am correcting the action of the Blogger app's show.

Here's my controller:

  Diff show @ articles = article. Fix (Param [: id]) @ comment = comment.new @ comments = comment. Address (Param [: id]) end  


Here is my show view - (which is partially presenting my comments) < / P> `

My comments are partial here: articles-path => gt;

  & lt; div & gt; & lt;% @ comments.each do | Comment | & Comment by: & lt; h4 & gt; & lt;% = comment Author_name% & gt; & lt; / h4 & gt; & lt; p class = "comment" & gt; & lt;% = comment.body% & gt; & lt; / p & gt; & lt;% end %>  

My problem is that when I show all comments from comments model on the show page through each iterator in comments in comments A I am getting the error, then I get this error:

Undefined method `for each '& lt; note: 0x007f12ef55d0d0 & gt;

show action I do not see any problem with my example variables, and each method I wrote has proper syntax. Does anyone know what this error is?

Your error basically means that you expect an array of comments O, but only a note saying the way you find that only one object will return, not an array. You need to adjust the following line:

@comments = Comment.find (params [: id])

If your relationships are correct , You should be able to change it with something like this:

@comments = article.comments


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

How to access user directory in lazarus? -

java - Gradle dependencies: compile project by relative path -