Hi all, I am new to rails, so please forget this newbie question.. I would like to add a function for calculating the elapsed time from the date of a post and the moment when the page is retrieved (Yes, I am sure 1milion of people did it already..) Considering that it should only process the data retrieved trough the model and controller, I would prefer to implement it as a simple utility function and not as a method of the controller. So, the question is: is there a proper way to add simple functions and have them accessible within the .rhtml templates scope? Thanks, Andrea --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hemm... I just discovered the existence of the app/helpers folder and it seems it does what I was looking for... ;) On Mar 19, 12:56 am, "And80" <a.f...-IWqWACnzNjyonA0d6jMUrA@public.gmane.org> wrote:> Hi all, > I am new to rails, so please forget this newbie question.. > I would like to add a function for calculating the elapsed time from > the date of a post and the moment when the page is retrieved (Yes, I > am sure 1milion of people did it already..) Considering that it should > only process the data retrieved trough the model and controller, I > would prefer to implement it as a simple utility function and not as a > method of the controller. So, the question is: is there a proper way > to add simple functions and have them accessible within the .rhtml > templates scope? > > Thanks, > Andrea--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
You might look at Rails'' time_ago_in_words (also known as distance_of_time_in_words_to_now). Assuming you have a created_at field in your Post model, you can do: This was posted <%= time_ago_in_words(@post.created_at) %> ago. On Mar 18, 2007, at 5:13 PM, And80 wrote:> > Hemm... I just discovered the existence of the app/helpers folder > and it seems it does what I was looking for... > > ;) > > On Mar 19, 12:56 am, "And80" <a.f...-IWqWACnzNjyonA0d6jMUrA@public.gmane.org> wrote: >> Hi all, >> I am new to rails, so please forget this newbie question.. >> I would like to add a function for calculating the elapsed time from >> the date of a post and the moment when the page is retrieved (Yes, I >> am sure 1milion of people did it already..) Considering that it >> should >> only process the data retrieved trough the model and controller, I >> would prefer to implement it as a simple utility function and not >> as a >> method of the controller. So, the question is: is there a proper way >> to add simple functions and have them accessible within the .rhtml >> templates scope? >> >> Thanks, >> Andrea > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---