Hi, I have the following code: <% @users.each do |u| -%> <tr class="<%= cycle("odd", "even") %>"> <td><%= u.name %>,<%= u.member_status_id %></td> <td><%= collection_select( u, :member_status_id, @member_statuses, :id, :name , { :class => "select"}, { :name => "member_status_id" } ) %> </td> </tr> <% 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? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
<%= 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 On Jan 13, 1:10 pm, wardenik <radek.anton...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > I have the following code: > <% @users.each do |u| -%> > <tr class="<%= cycle("odd", "even") %>"> > <td><%= u.name %>,<%= u.member_status_id %></td> > <td><%= collection_select( u, :member_status_id, > @member_statuses, :id, :name , { :class => "select"}, { :name => > "member_status_id" } ) %> </td> > </tr> > <% 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?-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
wardenik wrote in post #974738:> <% @users.each do |u| -%> > <tr class="<%= cycle("odd", "even") %>"> > <td><%= u.name %>,<%= u.member_status_id %></td> > <td><%= 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. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.