Home > Archive > Ruby > August 2005 > Rails Newbie - very simple question
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Rails Newbie - very simple question
|
|
| Joe Zambella 2005-08-30, 7:02 pm |
| Hello, I have a simple question based around the following example:
I have two model classes: Book and Author. The books table in my
database has an author_id, which links the book to the appropriate
author (aside: I know this isn't the best way to implement this, seeing
that a book can have multiple authors, but I'm trying to keep it simple
for the example and my own learning ;-)).
Now, I have my show.rhtml file for my Book class, where I want to
display all of the pertinent info: book title, date published, and,
most importantly to this example, the author's name.
My question is: given the book's author_id, what is the
preferred/recommended way to grab the auther's information from the
database from my book's show page?
Do I need to add a method to my Author class which, when provided with
the unique author_id, will return the necessary information?
Thanks!
Joe Z.
| |
|
|
| dave.burt@gmail.com 2005-08-31, 3:59 am |
| > My question is: given the book's author_id, what is the
> preferred/recommended way to grab the auther's information from the
> database from my book's show page?
# Try this:
Author.find(@book.author_id)
Now, this is such a basic question, I have to recommend some of the
following to get productive in Rails:
* find and go through a tutorial
* buy and go through Agile Web Development with Rails
* use the documentation at http://documentation.rubyonrails.com/ and
http://api.rubyonrails.com/
You can ask questions on the Rails mailing list
(http://lists.rubyonrails.org/mailman/listinfo/rails) or on IRC
(irc://irc.freenode.org/rubyonrails) as you learn.
(This isn't the most appropriate forum for Ruby on Rails specific
questions - you will get much better help from the resources I've
mentioned.)
Cheers,
Dave
|
|
|
|
|