Shikha Sharma
2008-Jun-04 09:54 UTC
how to set default month or day in f.date_select field
hi all, i have got a problem in my project. i have f.date_select field in my form and i want to set the default date = current date+30. but f.date_select is not allowing me to do so. there are options to set year only not month and day. see what i have followed: <% date_object = Time.now %> <% date_object = date_object.to_time.advance(:months => 1).to_date %> <%= f.date_select :valid_til, :default => {:year => date_object.year, :month => date_object.month}, :order => [:month, :day, :year ], :tabindex => "3" %> -------but this will work only for year not for month and day------ <%= f.date_select :valid_til, :start_year => date_object.year, :start_month => date_object.month, :start_day => date_object.day :order => [:month, :day, :year ], :tabindex => "3" %> -------but this also will work only for year not for month and day------ if anyone is known to this problem and solution please help me out from this. your help will be appreciated. thanks -- 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 -~----------~----~----~----~------~----~------~--~---
Denise Robinson
2008-Jun-04 17:59 UTC
Re: how to set default month or day in f.date_select field
Can you set it in the controller? For example, if the form is for a new entry: @new_record = Something.new @new_record.valid_til = date_object -- 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 -~----------~----~----~----~------~----~------~--~---
Phillip Koebbe
2008-Jun-04 21:05 UTC
Re: how to set default month or day in f.date_select field
Denise Robinson wrote:> Can you set it in the controller? > > For example, if the form is for a new entry: > > @new_record = Something.new > @new_record.valid_til = date_objectIf this for new records, which it sure does sound like, Denise''s idea is spot on. Just set it in the object when you create it and don''t futz with the rest. Peace, Phillip -- 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 -~----------~----~----~----~------~----~------~--~---
What would you do if this is for an existing record? I have nearly the same issue, but the problem for me is that the existing record is currenty null, and the date_select seems to be defaulting to today for its date. Dustin On Jun 4, 5:05 pm, Phillip Koebbe <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Denise Robinson wrote: > > Can you set it in the controller? > > > For example, if the form is for a new entry: > > > @new_record = Something.new > > @new_record.valid_til = date_object > > If this for new records, which it sure does sound like, Denise''s idea is > spot on. Just set it in the object when you create it and don''t futz > with the rest. > > Peace, > Phillip > -- > 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 -~----------~----~----~----~------~----~------~--~---
Phillip Koebbe
2008-Jun-15 11:02 UTC
Re: how to set default month or day in f.date_select field
Tubahead wrote:> What would you do if this is for an existing record? > > I have nearly the same issue, but the problem for me is that the > existing record is currenty null, and the date_select seems to be > defaulting to today for its date. > > Dustin > > On Jun 4, 5:05�pm, Phillip Koebbe <rails-mailing-l...-ARtvInVfO7m5VldFQK4jKA@public.gmane.orgt>Hello Dustin, You can do two things. If you must have a date in the form, then do the same thing for the existing record as you do for the new one: set it in the controller. Otherwise, if the date can actually be blank, add :include_blank => true to the f.date_select statement. Keep in mind that when using form_for, and therefore the f.* notation, FormBuilder will associate the date selector with the valid_til method on whatever object you pass into form_for. When initialized, whatever value you have in object.valid_til will be used to set the date selector''s date. If valid_til is nil, the current date will be used, unless :include_blank is true, and then it will be blank. Peace, Phillip -- 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks !! It worked great - I am quickly becoming a rails convert (this would have really sucked in php). This was what finally did what I sort of expected: <p>Date of Birth: <%= f.date_select :customers_dob, :start_year => 1920, :use_month_numbers => true, :include_blank => true %></p> Dustin On Jun 15, 7:02 am, Phillip Koebbe <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Tubahead wrote: > > What would you do if this is for an existing record? > > > I have nearly the same issue, but the problem for me is that the > > existing record is currenty null, and the date_select seems to be > > defaulting to today for its date. > > >Dustin > > > On Jun 4, 5:05�pm, Phillip Koebbe <rails-mailing-l...@andreas-s.net> > > HelloDustin, > > You can do two things. If you must have a date in the form, then do the > same thing for the existing record as you do for the new one: set it in > the controller. Otherwise, if the date can actually be blank, add > :include_blank => true to the f.date_select statement. > > Keep in mind that when using form_for, and therefore the f.* notation, > FormBuilder will associate the date selector with the valid_til method > on whatever object you pass into form_for. When initialized, whatever > value you have in object.valid_til will be used to set the date > selector''s date. If valid_til is nil, the current date will be used, > unless :include_blank is true, and then it will be blank. > > Peace, > Phillip > -- > 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 -~----------~----~----~----~------~----~------~--~---