I''m having trouble selecting a default value in my collection select. here is my code: f.collection_select(:item_type_id, @item_types, :id, :name) i want to select item_type.name = "N/A" for the default. any ideas? -- 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 -~----------~----~----~----~------~----~------~--~---
> f.collection_select(:item_type_id, @item_types, :id, :name) > > i want to select item_type.name = "N/A" for the default.The f...:item_type_id pattern will set the collection to whatever the target of the form_for has. I think you don''t want item_type_id to come back nil if the user selects nothing. That calls for a :prompt => ''N/A'' around the end Warning: If the form_for points to an item with a filled-out item_type_id, even if @item_types has no such item, you won''t get a prompt. Design Warning: Working with nils is evil. I would use a migration to add a real ''N/A'' to the item types, and I would park all unassigned item_type_id''s at it. That allows users to easily reset an item type back to ''N/A'' without you futzing around extra to provide a prompt. And without excessive nil checks in all your item type code. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> The f...:item_type_id pattern will set the collection to whatever the > target of the form_for has.Geez - before my aphasia derails anyone... The f...:item_type_id pattern will select the option matching whatever the target of the form_for has.> I think you don''t want item_type_id to come back nil if the user selects > nothing. That calls for a :prompt => ''N/A'' around the endI think you want item_type_id to come back nil if the user selects nothing. That calls for a :prompt => ''N/A'' around the end of the collection_select. Remaining post _might_ be okay... ;-) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Phlip wrote:>> f.collection_select(:item_type_id, @item_types, :id, :name) >> >> i want to select item_type.name = "N/A" for the default. > > The f...:item_type_id pattern will set the collection to whatever the > target > of the form_for has. > > I think you don''t want item_type_id to come back nil if the user selects > nothing. That calls for a :prompt => ''N/A'' around the end > > Warning: If the form_for points to an item with a filled-out > item_type_id, > even if @item_types has no such item, you won''t get a prompt. > > Design Warning: Working with nils is evil. I would use a migration to > add a > real ''N/A'' to the item types, and I would park all unassigned > item_type_id''s > at it. That allows users to easily reset an item type back to ''N/A'' > without > you futzing around extra to provide a prompt. And without excessive nil > checks in all your item type code.thanks for the reply! i just had to set @item.item_type_id = "1" in my new method in the controller. woohoo! i can finish coding now! -- 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 -~----------~----~----~----~------~----~------~--~---
Scott Kulik wrote:> I''m having trouble selecting a default value in my collection select. > > here is my code: > > f.collection_select(:item_type_id, @item_types, :id, :name) > > i want to select item_type.name = "N/A" for the default. > > any ideas?Use Like f.collection_select(:item_type_id, @item_types, :id, :name,:include_blank=>"N/A") it will pass null value to controller and in front end page also "N/A" will display -- 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 -~----------~----~----~----~------~----~------~--~---