Collection_select problem

Hi,

I have the following code:
<% @users.each do |u| -%>
<tr class="<%= cycle(“odd”, “even”) %>">

<%= u.name %>,<%= u.member_status_id %>
<%= collection_select( u, :member_status_id,
@member_statuses, :id, :name , { :class => “select”}, { :name =>
“member_status_id” } ) %>

<% end %>

The select is generating fine, apart from the fact that appropriate
options are not selected.

<%= u.member_status_id %> is returning correct values for the records
(1,2,3,4)
MemberStatus.all.inspect returns:

[#<MemberStatus id: 1, name_pl: “Obserwator”, name_en: “Observer”,
created_at: “2011-01-10 15:02:58”, updated_at: “2011-01-10 15:02:58”,
created_by: nil, updated_by: nil>, #<MemberStatus id: 2, name_pl:
“Baby”, name_en: “Baby Member”, created_at: “2011-01-10 15:02:58”,
updated_at: “2011-01-10 15:02:58”, created_by: nil, updated_by: nil>,
#<MemberStatus id: 3, name_pl: “Pełne”, name_en: “Full Member”,
created_at: “2011-01-10 15:02:58”, updated_at: “2011-01-10 15:02:58”,
created_by: nil, updated_by: nil>, #<MemberStatus id: 4, name_pl:
“Alumn”, name_en: “Alumni”, created_at: “2011-01-10 15:02:58”,
updated_at: “2011-01-10 15:02:58”, created_by: nil, updated_by: nil>,
#<MemberStatus id: 5, name_pl: “Zrezygnowa\305\202”, name_en:
“Resigned”, created_at: “2011-01-10 15:02:58”, updated_at: “2011-01-10
15:02:58”, created_by: nil, updated_by: nil>, #<MemberStatus id: 6,
name_pl: “Inactive”, name_en: “Inactive”, created_at: “2011-01-10
15:02:58”, updated_at: “2011-01-10 15:02:58”, created_by: nil,
updated_by: nil>]

But still, the helper is not putting the “selected” where it should.
Any advice?

<%= u.collection_select( :member_status_id,
@member_statuses, :id, :name , { }, { :class => “select”, :name =>
“member_status_id” })%>

I would try this. the first hash set is for options, the second is for
HTML options. It looks like your passing args in the wrong place

wardenik wrote in post #974738:

<% @users.each do |u| -%>

"> <%= u.name %>,<%= u.member_status_id %> <%= collection_select( u, :member_status_id, blah blah blah %>

Please, please, please get that collection_select data access out of the
view.

If you have 100 users, how many times will you exec that code?

Retrieve your @member_statuses in the controller, once, and use that var
in the view.