I want to set a default on a collection select. There must be a way to do this, but how?> :default => "kdjng" (?)-- 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.
Pale Horse wrote:> I want to set a default on a collection select. There must be a way to > do this, but how? > >> :default => "kdjng" (?)<%= collection_select(:category, :id, @categories, :id, :name, {},{:size=>10}) %> will have the value of @category selected so you can set the default value to @category and then use the collection select. This was the method I used as I had to make different categories as default selected one for different users.There might be some better ways too.Eager to know them too. -- 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.
Charanya Nagarajan wrote:> <%= collection_select(:category, :id, @categories, :id, :name, > {},{:size=>10}) %> > will have the value of @category selected > so you can set the default value to @category and then use the > collection select. > > This was the method I used as I had to make different categories as > default selected one for different users.There might be some better ways > too.Eager to know them too.Thanks for your response.>> <%= f.collection_select :brand, [''Brand 1'', ''Brand 2'', ''Brand 3'', ''Brand 4''], :to_s, :to_s %>The above is the syntax I''m currently using. In theory, the default brand would be Brand 1, correct? So when a form containing this collection gets submitted (without amending the collection), Brand 1 is parsed as the one selected. At least, that''s what I''m looking for. -- 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.
If you want to have a default selected value then you can use select_tag <%= select_tag :brand, options_for_select([''Brand 1'', ''Brand 2'', ''Brand 3'', ''Brand 4''], "Brand 2") %> You had used this <%= f.collection_select :brand, [''Brand 1'', ''Brand 2'', ''Brand 3'', ''Brand 4''], :to_s, :to_s %> in case if the form f object is for article then u can use <%= select_tag ''article[brand]'', options_for_select([''Brand 1'', ''Brand 2'', ''Brand 3'', ''Brand 4''], "Brand 2") %> Hope this helps. -- 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.
Charanya Nagarajan wrote:> If you want to have a default selected value then you can use select_tag > > <%= select_tag :brand, options_for_select([''Brand 1'', ''Brand 2'', ''Brand > 3'', ''Brand 4''], "Brand 2") %> > > You had used this > <%= f.collection_select :brand, [''Brand 1'', ''Brand 2'', ''Brand 3'', ''Brand > 4''], :to_s, :to_s %> > > in case if the form f object is for article then u can use > > <%= select_tag ''article[brand]'', options_for_select([''Brand 1'', ''Brand > 2'', ''Brand 3'', ''Brand 4''], "Brand 2") %> > > > Hope this helps.Thank you :) -- 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.