Select dropdown based off join table's include?

I have a “New Photo” view where I’d like to provide a select dropdown
of the user’s favorite locations. Getting the data for a user’s
favorites is no problem, but I’m not sure how to put the location name
into the select form.

def new
@photo = Photo.new
@favorites = current_user.favorites.find(:all, :include
=> :location)
end

<%= f.collection_select :location_id,
@favorites, :location_id, :location_id, { :include_blank => true }, {}
%>

(the 4th parameter in the f.collection_select above is my problem)

On a related note, is there a more efficient way to query for the
locations’ id & name w/o returning all fields? Or is it not really
that much of a performance issue?

Any tips would be greatly appreciated. Thanks in advance.

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Saturday 31 May 2008 20:06:58 Sav wrote:

Getting the data for a user’s
favorites is no problem, but I’m not sure how to put the location
name into the select form.

Add location_name as a method on User:

def location_name
self.location.name
end

Then you can pass :location_name to collection_select.

Ciao,
Sheldon.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFIQcDWpGJX8XSgas0RAgwCAJ9bRiEJ/EJau/YZ/NSXwHeF6aEHyACgqGRa
5L//c/Q5jNVZzN4DsYRrQ2c=
=UNXf
-----END PGP SIGNATURE-----