Ok, this should be simple but I am finding it''s not and previous postings don''t seem to shed too much light on this. I have a select_tag with 4 values pulled in via a helper: def filter_hours filter_hours = [ ["1 hour", 1], ["24 hours", 24], ["7 days", 168], ["14 days", 336], ] end The select_tag looks like the following: select_tag :order_hours, options_for_select(filter_hours, :selected => @selected_order_hours) @selected_order_hours is being set in the controller when the form is posted. It comes back as either 1, 24, 168, 336 and is definitely being set as confirmed through logging and printing from the view. However, the selected valued is never set! I have tried all combinations of :selected, selected=, etc to no avail. What''s wrong? Thanks, Scott --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Anyone have any ideas on this one? On May 11, 12:12 pm, Scott <tamosu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Ok, this should be simple but I am finding it''s not and previous > postings don''t seem to shed too much light on this. > > I have a select_tag with 4 values pulled in via a helper: > > def filter_hours > filter_hours = [ > ["1 hour", 1], > ["24 hours", 24], > ["7 days", 168], > ["14 days", 336], > ] > end > > The select_tag looks like the following: > > select_tag :order_hours, options_for_select(filter_hours, :selected => > @selected_order_hours) > > @selected_order_hours is being set in the controller when the form is > posted. It comes back as either 1, 24, 168, 336 and is definitely > being set as confirmed through logging and printing from the view. > > However, the selected valued is never set! > > I have tried all combinations of :selected, selected=, etc to no > avail. > > What''s wrong? > > Thanks, > > Scott--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Bob Showalter
2007-May-15 13:14 UTC
Re: options_for_select - how to set the selected value?
On 5/11/07, Scott <tamosunas-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> The select_tag looks like the following: > > select_tag :order_hours, options_for_select(filter_hours, :selected => > @selected_order_hours) > > @selected_order_hours is being set in the controller when the form is > posted. It comes back as either 1, 24, 168, 336 and is definitely > being set as confirmed through logging and printing from the view. > > However, the selected valued is never set!It should just be: options_for_select(filter_hours, @selected_order_hours) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Tried that ... doesn''t work. @selected_order_hours is definitely being set. Any other ideas? Thanks, Scott On May 15, 6:14 am, "Bob Showalter" <showa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 5/11/07, Scott <tamosu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > The select_tag looks like the following: > > > select_tag :order_hours, options_for_select(filter_hours, :selected => > > @selected_order_hours) > > > @selected_order_hours is being set in the controller when the form is > > posted. It comes back as either 1, 24, 168, 336 and is definitely > > being set as confirmed through logging and printing from the view. > > > However, the selected valued is never set! > > It should just be: > > options_for_select(filter_hours, @selected_order_hours)--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Figured it out. Had to change: select_tag :order_hours, options_for_select(filter_hours, @selected_order_hours) to select_tag :order_hours, options_for_select(filter_hours, @selected_order_hours.to_i) Picky picky! Scott On May 27, 3:37 pm, Scott <tamosu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Tried that ... doesn''t work. @selected_order_hours is definitely being > set. > > Any other ideas? > > Thanks, > > Scott > > On May 15, 6:14 am, "Bob Showalter" <showa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > On 5/11/07, Scott <tamosu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > The select_tag looks like the following: > > > > select_tag :order_hours, options_for_select(filter_hours, :selected => > > > @selected_order_hours) > > > > @selected_order_hours is being set in the controller when the form is > > > posted. It comes back as either 1, 24, 168, 336 and is definitely > > > being set as confirmed through logging and printing from the view. > > > > However, the selected valued is never set! > > > It should just be: > > > options_for_select(filter_hours, @selected_order_hours)--~--~---------~--~----~------------~-------~--~----~ 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 wrote in post #251131:> Figured it out. Had to change: > > select_tag :order_hours, options_for_select(filter_hours, > @selected_order_hours) > to > select_tag :order_hours, options_for_select(filter_hours, > @selected_order_hours.to_i) > > Picky picky! > > Scottwas stuck on a similar problem, my solution was <%= f.select :grade, ((1..9).to_a) %> -- 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.