Here are three methods I use in a game. They're in the model that
keeps track of scores etc.

   def update_start_time()
        self.update_attribute(:start_time, Time.now)
    end

     def time_since_start
       time_since_start = Time.now - self.start_time
     end

This part updates the database:
   def update_game_duration()
        self.update_attribute(:game_duration, time_since_start)
    end

Then in the controller, I update the page display of the time as so:
page.replace_html "displayGameTime", :inline => "<%= 'Time: ' + session
[:current_game].time_since_start.to_i.to_s  + ' sec'  %>"

Converting it to minutes or hours is something I haven't got round to.

Ed

On Oct 16, 7:05 pm, netdieter <[email protected]>
wrote:
> I'm new to rails and i'm glad to manage my first steps with AS.
> I like it
> But now i stuck.
> I have a model nemed effort, which consists of two datetime (start and
> end)
> How do i calculate the difference in hours and how do i get it on the
> view?
>
> Thanx,
> Dieter
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"ActiveScaffold : Ruby on Rails plugin" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/activescaffold?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to