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? Cheers, Mick -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Mick wrote:> 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? > > Cheers, > > Mick > >As a Helper to the view? Cheers Mohit. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Mohit Sindhwani wrote:> Mick wrote: >> Mick >> >> > As a Helper to the view? > Cheers > Mohit.Smart! Thanks! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
what I might do is add a method to the Time class
class Time
def difference_in_days(t = Time.now)
((self - t).abs / 86400).to_int
end
end
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 = Time.now + 10.days
due_date.difference_in_days
On 3/29/07, Mick
<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:>
> Mohit Sindhwani wrote:
> > Mick wrote:
> >> Mick
> >>
> >>
> > As a Helper to the view?
> > Cheers
> > Mohit.
>
> Smart! Thanks!
>
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---