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) using123.seconds
. . ). Use theduration
for good formatting (this is not correct. In, you probably want attribute readers and authors to defineActiveSupport :: duration
objects, instead of integers simplyduration = (new_disabled)
andduration
Do, which internally callread_attribute
/write_attribute
with integer arguments.
Comments
Post a Comment