[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

How do I access a my :include data in my Ruby SQL results

3bt8y Buss

6/2/2009 5:09:00 AM

I am new to Ruby on Rails, so this is probably a very easy answer:

Two tables -- one of authors, one of books
authors belong_to books
In my situation, each book can only have one author.


I want to list all the books (with the author name) in a Select field.

@all_books = Book.find( :all, :include => [:authors] )

Then, I create the Select statement:

select(:book, :id, @all_books.collect {|b| [b.book_name + " (" +
b.author_name + ")", b.id ] }) %>


This creates an error because I'm trying to include the author_name.
When I run @all_books.inspect, I can see the author info in there.

So, how do I actually access the author data from that array (or object,
or whatever the correct terminology is)?

Thanks!
--
Posted via http://www.ruby-....

2 Answers

Brian Candler

6/2/2009 8:04:00 AM

0

DL Buss wrote:
> I am new to Ruby on Rails, so this is probably a very easy answer:

Rails (the web framework) is not the same as Ruby (the programming
language). So you would do much better to ask your question on a Rails
mailing list or forum. They are linked from rubyonrails.org
--
Posted via http://www.ruby-....

Mark Thomas

6/2/2009 9:29:00 AM

0

Agreed that it is better to use the Rails list/group. But you probably
want b.author.author_name.