How do I select a default value in a blank form when using select vs select_tag? For example, I have a collection of states and I want the local state to be automatically selected when filling out the form. Am I stuck with using select_tag and options_for_select? Thanks. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
In ur new action initialize that attribute to whatever value u wish. Check the docs it may have an option to set a default value. Sent from my iPhone On Jan 18, 2008, at 5:05 PM, partydrone <partydrone-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > How do I select a default value in a blank form when using select vs > select_tag? > > For example, I have a collection of states and I want the local state > to be automatically selected when filling out the form. > > Am I stuck with using select_tag and options_for_select? > > Thanks. > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Jan 19, 1:02 pm, Bcp <bcpar...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> In ur new action initialize that attribute to whatever value u wish. > Check the docs it may have an option to set a default value. > > Sent from my iPhone > > On Jan 18, 2008, at 5:05 PM, partydrone <partydr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:Hi, Even when this value is set in the action, first element in the select list is populated by default when the html is rendered. Regards, HAK --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
partydrone wrote:> How do I select a default value in a blank form when using select vs > select_tag?select is designed to choose a particular value for an attribute of an object. The call is: select object, method, choices, options, html_options The given method on the given object is called and the item from the choices that matches (if any) will be selected. If this is for a create form, then set the new object''s attribute to the initial default you want in your method: def new @item = Item.new @item.state = default_state_value end Then, in the view: <%= select :item, :state, ... -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---