collection_select and selected_value

Hi,

I am using collection_select to build a drop down list. I would like to have the current value selected. How can I do that?

My current code is straight from the example in Pragmatic Programmers book [2nd ed, p480] copying here for reference.

<%= @users = User.find(:all, :order => "name" ) form.collection_select(:name, @users, :id, :name) %>

I went through the api docs and found that there is a way to do this using selected_value, but an example would be much appreciated.

raj

Rajkumar S wrote:

I am using collection_select to build a drop down list. I would like to have the current value selected. How can I do that?

<%= @users = User.find(:all, :order => "name" ) form.collection_select(:name, @users, :id, :name) %>

Can you pass in :selected => my_favorite_id ?

Thanks a lot for your reply!