undefined method 'each' Ruby on Rails -


apologies in advance, newbie trying head around rails.

my view @ bottom works when use:

def show @posts = post.all end 

however in controller have:

def show @posts = post.find_by_category_id params[:id]; end 

in view have

<%= @posts.each |post| %> <%= post.title %> <% end %> 

some please explain why error. should use. category_id foreign key on post table.

look @ http://api.rubyonrails.org/classes/activerecord/findermethods.html#method-i-find_by

finds first record matching specified conditions 

find_by_ return 1 post, not collection. not able use each.


Comments

Popular posts from this blog

python - argument must be rect style object - Pygame -

c++ - Qt setGeometry: Unable to set geometry -

webrtc - Which ICE candidate am I using and why? -