Getting started with Ruby on Rails and Relationships

Hi,

As a side-note, instead of doing @results = Book.find(:all, :conditions => { :author_id => entry.id})

You can do this: @results = Author.find( entry.id).books

Or if entry is already an author instance @results = entry.books

This also infers that your relations ships are: has_many :books and belongs_to :author

On to your actual question, you would want to do:

<% @results.each do |result| %> <%= h(book.title) %> <%= h(book.description) %> <%= h(book.author.firstname) %> <%= h(book.author.lastname) %> <% end %>

If this gives you problems, check that your relationships are like I said above:

has_many :books on the author model belongs_to :author on the book model

Hope this helps.

Cheers, James