I have a model with a column called start and typed as :datetime.
I would like to be able to calculate how many days there are until the start date and time.
Currently, I have a simple view that does
<%= @myModel.start - Time.now %>
This gives me something like -650.878217378
- How can I get it to display days and hours until that date
- It seems wrong to be doing this in the view – should I make another instance variable for this calc in my view?
Thanks!
The
distance_of_time_in_words/distance_of_time_in_words_to_nowview helpers will produce human friendly strings, see the rails docs for examples.If you are going to be doing calculations like this and the rails provided view helpers don;t meet your needs, I’d write my own view helpers. I don’t think there’s anything ‘naughty’ about doing