views:

22

answers:

1

Does anyone know a better way of displaying the contents of an activerecord result set as a select box.

I would like todo this

@users = User.all
<%= f.select_box :users, options_for_select(@users) %>

But for now I need to parse all the users into a multidimensional array with a sub array [username,user_id]

Any ideas?

+1  A: 

I generally use collection_select

<%= f.collection_select :user_id, User.all, :user_id, :username, :prompt => true %>

Reference: http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#M002303

Geoff Lanotte