Hello, I would like to list all the chapter description related to a particuler title on catalog/list.rhtml. There are two associated tables ''Title'' and ''Chapter''. I have written the following but does not work. Can anyone assist me on this issue? #Title table book_name :string chapter_id :integer #Chapter table description :string class Title < ActiveRecord::Base has_many :chapters class Chapter < ActiveRecord::Base belongs_to :title class CatalogController < ApplicationController def list @title = Title.find(params[id]) end list_rhtml <table> <% for title in @titles %> <tr> <td><%= link_to title.book_name, :action => ''show'', :id=> title %></td> <td> </td> <td><%= title.chapter.description %> </tr> <% end %> </table> -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
if title has_many chapters, then chapters need a title_id, not titles a chapter_id if you correct this, then in your view this should do the trick: <table> <% @titles.each do |title| %> <tr> <td><%= link_to title.book_name, :action => ''show'', :id=> title %></td> <td> </td> <% title.chapters.each do |chapter| %> <td><%= chapter.description %></td> <% end %> </tr> <% end %> </table> -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thorsten Muller wrote:> if title has_many chapters, then chapters need a title_id, not titles a > chapter_id > > if you correct this, then in your view this should do the trick: > > <table> > <% @titles.each do |title| %> > <tr> > <td><%= link_to title.book_name, :action => ''show'', :id=> title > %></td> > <td> </td> > <% title.chapters.each do |chapter| %> > <td><%= chapter.description %></td> > <% end %> > </tr> > <% end %> > </table>Thank you very very much. With your assistance, it came out the way I wanted. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---