I don''t really understand how forms are generated so this may be a very easy question. I have some code that does a date select: <p> <%= f.label :StartDate%> <br /> <%= f.date_select :start_date %> </p> <p> <%= f.label :EndDate %> <br /> <%= f.date_select :end_date %> </p> Which results in the following when posted: Checked Out Times: Start: 05-20-2009 18:30:20 End: 05-21-2009 19:30:20 However, when I go to edit the time I see the following in the date select: Start Time: 20:18 End Time : 20:19 This occurs because my times are stored in the database as: | 20:19:17 | 20:20:17 or as mm:hh:ss Thus when the edit occurs it grabs the seconds and the minutes. Is there a way to change the form to properly select the correct time? I''ve tried :order => [:hour, :minute, :second] like here (http://stackoverflow.com/questions/732806/how-do-i-handle-date-objects-in-ruby-on-rails-forms) but haven''t found a way to do it. Am I using the wrong type of form? Should I be querying the database in a different way? -- Posted via http://www.ruby-forum.com/.
If you save it in the database as a datetime then all should be well. If that is not possible then you could have a virtual datetime member that you setup in a filter after reading it from the db and this is what goes to the form. You can then put the code converting it back to your homespun format in another filter before writing to the db. 2009/5/21 Tyler Knappe <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>> > I don''t really understand how forms are generated so this may be a very > easy question. > > I have some code that does a date select: > > <p> > <%= f.label :StartDate%> <br /> > <%= f.date_select :start_date %> > </p> > > <p> > <%= f.label :EndDate %> <br /> > <%= f.date_select :end_date %> > </p> > > Which results in the following when posted: > > Checked Out Times: > Start: 05-20-2009 18:30:20 > End: 05-21-2009 19:30:20 > > However, when I go to edit the time I see the following in the date > select: > > Start Time: 20:18 > End Time : 20:19 > > This occurs because my times are stored in the database as: > > | 20:19:17 | 20:20:17 or as mm:hh:ss > > Thus when the edit occurs it grabs the seconds and the minutes. Is > there a way to change the form to properly select the correct time? > I''ve tried :order => [:hour, :minute, :second] like here > ( > http://stackoverflow.com/questions/732806/how-do-i-handle-date-objects-in-ruby-on-rails-forms > ) > but haven''t found a way to do it. Am I using the wrong type of form? > Should I be querying the database in a different way? > -- > 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 -~----------~----~----~----~------~----~------~--~---
On May 21, 2:28 am, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> If you save it in the database as a datetime then all should be well. IfHave you tried using the :db format?: Time.now.to_s(:db) # this forces the save to the db in compatable formats -- Wayne> that is not possible then you could have a virtual datetime member that you > setup in a filter after reading it from the db and this is what goes to the > form. You can then put the code converting it back to your homespun format > in another filter before writing to the db. > > 2009/5/21 Tyler Knappe <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > > > > I don''t really understand how forms are generated so this may be a very > > easy question. > > > I have some code that does a date select: > > > <p> > > <%= f.label :StartDate%> <br /> > > <%= f.date_select :start_date %> > > </p> > > > <p> > > <%= f.label :EndDate %> <br /> > > <%= f.date_select :end_date %> > > </p> > > > Which results in the following when posted: > > > Checked Out Times: > > Start: 05-20-2009 18:30:20 > > End: 05-21-2009 19:30:20 > > > However, when I go to edit the time I see the following in the date > > select: > > > Start Time: 20:18 > > End Time : 20:19 > > > This occurs because my times are stored in the database as: > > > | 20:19:17 | 20:20:17 or as mm:hh:ss > > > Thus when the edit occurs it grabs the seconds and the minutes. Is > > there a way to change the form to properly select the correct time? > > I''ve tried :order => [:hour, :minute, :second] like here > > ( > >http://stackoverflow.com/questions/732806/how-do-i-handle-date-object... > > ) > > but haven''t found a way to do it. Am I using the wrong type of form? > > Should I be querying the database in a different way? > > -- > > Posted viahttp://www.ruby-forum.com/.
WJSimacek wrote:> On May 21, 2:28�am, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> If you save it in the database as a datetime then all should be well. �If > > Have you tried using the :db format?: > > Time.now.to_s(:db) # this forces the save to the db in > compatable formats > > -- WayneI''m not sure how to add this to the code. I''ve found form helpers very unintuitive. Can anyone point me towards a good guide or documentation? Thanks, -Tyler -- Posted via http://www.ruby-forum.com/.
2009/5/21 Tyler Knappe <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>> > WJSimacek wrote: > > On May 21, 2:28�am, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > >> If you save it in the database as a datetime then all should be well. > �If > > > > Have you tried using the :db format?: > > > > Time.now.to_s(:db) # this forces the save to the db in > > compatable formats > > >I may have to be corrected, but I don''t think this is necessary. If the db column is datetime (as defined in the migration and schema.rb) then the value in a DateTime object should be written (and read) automatically in the appropriate format. Colin> > > -- Wayne > > I''m not sure how to add this to the code. I''ve found form helpers very > unintuitive. Can anyone point me towards a good guide or documentation? > > Thanks, > -Tyler > -- > 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 -~----------~----~----~----~------~----~------~--~---
Colin Law wrote:> 2009/5/21 Tyler Knappe <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > >> > >> > > I may have to be corrected, but I don''t think this is necessary. If the > db > column is datetime (as defined in the migration and schema.rb) then the > value in a DateTime object should be written (and read) automatically in > the > appropriate format. > > ColinWould this be true of date and time fields? That is how I am storing them right now.. I''m tempted to make the switch to datetime; it just seems to be easier in the long run and I now know how to filter the date and times from the single field. -- Posted via http://www.ruby-forum.com/.
I don''t know about date and time types. Colin 2009/5/21 Tyler Knappe <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>> > Colin Law wrote: > > 2009/5/21 Tyler Knappe <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > > >> > > >> > > > > I may have to be corrected, but I don''t think this is necessary. If the > > db > > column is datetime (as defined in the migration and schema.rb) then the > > value in a DateTime object should be written (and read) automatically in > > the > > appropriate format. > > > > Colin > > Would this be true of date and time fields? That is how I am storing > them right now.. I''m tempted to make the switch to datetime; it just > seems to be easier in the long run and I now know how to filter the date > and times from the single field. > -- > 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 -~----------~----~----~----~------~----~------~--~---