Forum: Ruby on Rails Rails Logic

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
6f4989f18fb2315d4b1db15cccb29ecf?d=identicon&s=25 Mick (Guest)
on 2007-03-29 12:53
I want to write a function that takes a date in the future and returns
how many days are left until that date. However, I am not sure where it
should go - the model seems to be purely for database interactions, and
the controller is executed before page display (and I want to call my
function dynamically inside a loop, in the view),

anyone know where it should be placed?


34a7615f38496a5dafbb3e6b721c435e?d=identicon&s=25 Mohit Sindhwani (Guest)
on 2007-03-29 13:00
(Received via mailing list)
Mick wrote:
> Mick
As a Helper to the view?
6f4989f18fb2315d4b1db15cccb29ecf?d=identicon&s=25 Mick (Guest)
on 2007-03-29 13:05
Mohit Sindhwani wrote:
> Mick wrote:
>> Mick
> As a Helper to the view?
> Cheers
> Mohit.

Smart! Thanks!
A2c85dc5ee81b12e3cc0a6522e8d079d?d=identicon&s=25 Chris Hall (au5lander)
on 2007-03-29 15:52
(Received via mailing list)
what I might do is add a method to the Time class

class Time
  def difference_in_days(t =
    ((self - t).abs / 86400).to_int

not sure where to put this (environment.rb perhaps?) to have it
automatically available in Rails.  could also put it in lib directory,
call it time_extentions.rb or whatever, and use require.

due_date = + 10.days

This topic is locked and can not be replied to.