Hi there, I created my own time helper which stores hash values for name, and value of 12 hr times in an array. The problem is, I''m lost on how to create the drop down menu in the view that utilizes the hash data? How do i access the values hash nested in the array? Here''s the helper that generates the selection options in the drop- down menu: def time_to_12hr @time_values = [{:twelve => "12 AM", :twentyfour => 0}] clock24hr = 0 designator = ''AM'' 2.times do for number in 1..11 clock24hr += 1 @time_values << {:twelve => "#{number} #{designator}", :twentyfour => clock24hr} end if designator == ''AM'' @time_values << {:twelve => "12 PM", :twentyfour => 12} end clock24hr = 12 designator = ''PM'' end return @time_values end end I then collect the values in the view like this which would be used by the select tag that generates the drop down: <% @time = time_to_12hr %> What would the select tag look like to access :twelve as the name and :twentyfour as the value for each option? I can''t get my head around it. Thanks, -A --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I am not sure, the way you mean a helper is correct. because as i know helper is used to convert or as a function in view like : <% time_to_12hr(Time.now) %>. If I see your def method above, i prefer to put it in application.rb and create before_filter :time_to_12hr in required controller. Because i see that all values of array are already stored in @time_values so you not need the script below.> <% @time = time_to_12hr %> >This is my way : ---------------------- Application Controller ---------------------- def time_to_12hr [see the posted original script] end ---------------------- Indonesia_controller.rb ---------------------- class IndonesiaController < ApplicationController before_filter :time_to_12hr def index end end -------------- VIEW example: index.rhtml -------------- <%= select_tag "my_time", "<option value=\"none\">Select Your Time</option>"+ options_for_select(@time_values) %> What do you think ? ~*~*~*~*~*~*~*~*~*~*~*~*~*~ Reinhart Ariando YM:Booking2Heaven WEB: teapoci.blogspot.com ~*~*~*~*~*~*~*~*~*~*~*~*~*~ -- 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 -~----------~----~----~----~------~----~------~--~---
Hi there, I think it makes sense to have this method in the application controller as you suggest. The problem I''m still facing is that the drop down options look like this: twelve12 AMtwentyfour0 twelve1 AMtwentyfour1 etc... So its compressing the hash when what I want is the hash value of :twelve to be the name of the select option, and the hash value of :twentyfour to be the value for each of the options so it displays like this: 12 AM 1 AM etc... And tied to each option name is the corresponding value, 0, 1, etc. What needs to change in the select tag to make this happen? Thanks, -A On Feb 22, 2:18 am, Visit Indonesia 2008 <rails-mailing-l...@andreas- s.net> wrote:> I am not sure, the way you mean a helper is correct. because as i know > helper is used to convert or as a function in view like : > > <% time_to_12hr(Time.now) %>. > > If I see your def method above, i prefer to put it in application.rb > and create before_filter :time_to_12hr in required controller. Because i > see that all values of array are already stored in @time_values so you > not need the script below. > > > <% @time = time_to_12hr %> > > This is my way : > > ---------------------- > Application Controller > ---------------------- > > def time_to_12hr > > [see the posted original script] > > end > > ---------------------- > Indonesia_controller.rb > ---------------------- > class IndonesiaController < ApplicationController > before_filter :time_to_12hr > > def index > end > > end > > -------------- > VIEW example: index.rhtml > -------------- > > <%= select_tag "my_time", "<option value=\"none\">Select Your > Time</option>"+ options_for_select(@time_values) %> > > What do you think ? > > ~*~*~*~*~*~*~*~*~*~*~*~*~*~ > Reinhart Ariando > YM:Booking2Heaven > WEB: teapoci.blogspot.com > ~*~*~*~*~*~*~*~*~*~*~*~*~*~ > -- > Posted viahttp://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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I create like this : def time_to_12hr @time_values = [] for number in 1..24 if number < 13 @time_values << "#{number}+AM" else @time_values << "#{number-13}+PM" unless number == 24 @time_values << "0" end end end end ..... VIEW ..... <%= select_tag "my_time", "<option value=\"none\">Select Your Time</option>"+ options_for_select(@time_values) %> -- 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 -~----------~----~----~----~------~----~------~--~---
Forget my footer...he...he..he... ~*~*~*~*~*~*~*~*~*~*~*~*~*~ Reinhart Ariando YM:Booking2Heaven WEB: teapoci.blogspot.com ~*~*~*~*~*~*~*~*~*~*~*~*~*~ -- 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 -~----------~----~----~----~------~----~------~--~---
contact me to my email, booking2heaven[at]yahoo.com, I am always interested with ruby on rails. I am not good in Java and middle intermediate in PHP. Thank you. ~*~*~*~*~*~*~*~*~*~*~*~*~*~ Reinhart Ariando YM:Booking2Heaven WEB: teapoci.blogspot.com ~*~*~*~*~*~*~*~*~*~*~*~*~*~ -- 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 -~----------~----~----~----~------~----~------~--~---