Loading data from two associated tables

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

<% for title in @titles %> <% end %>
<%= link_to title.book_name, :action => 'show', :id=> title %>   <%= title.chapter.description %>

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:

<% @titles.each do |title| %> <% title.chapters.each do |chapter| %> <% end %> <% end %>
<%= link_to title.book_name, :action => 'show', :id=> title %>   <%= chapter.description %>

Thorsten M. 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:

<% @titles.each do |title| %> <% title.chapters.each do |chapter| %> <% end %> <% end %>
<%= link_to title.book_name, :action => 'show', :id=> title %>   <%= chapter.description %>

Thank you very very much. With your assistance, it came out the way I
wanted.