Reputation: 5631
I am storing time as string in database. But at the view layer I want make sure that format for the time is validate.
Plus , how can add a lookup show am and pm.
At controller merge the 2 view level field into one and store in model.
Upvotes: 0
Views: 97
Reputation: 55
Datetime is gonna be the best option for you. Storing a string for this purpose has no sense.
Moreover, it's gonna be easier to format, like
article.published_at.strftime("Published at: %d/%m/%Y %H:%M")
will be something like:
Published at: 31/05/2012 11:57
Upvotes: 1
Reputation: 4766
Why don't you store as datetime
or time
in your database, and use time_select
helper method?
http://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html#method-i-time_select
Upvotes: 2