ruby - Using a duration field in a Rails model -


I am looking for the best way to use a duration field in the Rail model. I should have format HH: MM: SS (ex: 01:30:23). The database used is locally scalable and postgres in production.

I would also like to work with this area so that I can see all things in the field and I can come with the total time of all the objects of that model and thus will end with something like this: / P>

30 records total 45 hours, 25 minutes and 34 seconds.

>
  • Store as an integer in your database (number of seconds, probably)
  • Your login form will depend on the exact usage case. Dropdowns are painful; Better to use small text fields for hours in hours + minutes + seconds.
  • Just run a SUM query on the duration column for a large total production. If you use an integer, it's easy and fast.

Additionally:

  • Use the helper to display the duration in your scenes. You can easily make an integer of ActiveSupport :: duration ( 123 with integer from database) using 123.seconds . . ). Use the duration for good formatting (this is not correct. In, you probably want attribute readers and authors to define ActiveSupport :: duration objects, instead of integers simply duration = (new_disabled) and duration Do, which internally call read_attribute / write_attribute with integer arguments.

Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -