request - Get all works' title from artist in Rails -


so here's want get: each artist in table, want post it's name , last 3 works made.

here's have far:

 class artist < activerecord::base attr_accessible :image, :name has_many :works end class work < activerecord::base attr_accessible :artist_id, :exhibition_id, :image, :title belongs_to :artist belongs_to :exhibition end <% @artists.each |artist| %> <div class="one-artist"> <h3><%= artist.name %></h3> <div class="artist-work first-work"> <%= artist.works.title %> </div> <% end %> 

i thought acceptable way approach artists works, seems fail.

it gives me following repsonse:

undefined method `title' #<activerecord::relation:0x00000102e89038> 

works relation contains of works. if want access, say, first should write artist.works.first.title


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -