Let''s see the relevant bits of your User and Friendship models. If you
define the relationship correctly, AR should give you e.g., a .friends
method on your User instances, which should return a collection of User
objects. You should be able to do something like:
collection_select(:bet, :opponent_id, current_user.friends, :id,
:full_name)
-Roy
-----Original Message-----
From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
[mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] On Behalf Of
Adam Dorsey
Sent: Sunday, July 20, 2008 7:47 PM
To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
Subject: [Rails] collection_select with HABTM relationship
I have a collection set...
<%= collection_select(:bet, :opponent_id, Friendship.find(:all,
:conditions => [ "user1_id = ?", current_user ], :order =>
"id") , :id,
:id) %>
..wors fine. But I want to return the users first+last name based on the
user -> frienship relationship.
I tried to do something like this...
<%= collection_select(:bet, :opponent_id, Friendship.find(:all,
:conditions => [ "user1_id = ?", current_user ], :order =>
"id") , :id,
@bet.user.first_name) %>
It actually returns the correct First name, but throws an error, because
it thinks the actual name is an undefined method.
??
--
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@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---