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
Post a Comment