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

c# - Better 64-bit byte array hash -

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

php - Zend Framework / Skeleton-Application / Composer install issue -