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.

??

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