Thanks Matt.
This helps a lot. Yes i will rename the time model.

On Tue, Aug 17, 2010 at 12:17 AM, Matt Jones <[email protected]> wrote:

>
> On Aug 16, 2010, at 11:43 PM, Abbasi Ujjainwala wrote:
>
> Hi,
>> Appreciating the active hobo community I am taking this courage.
>> I am trying out hobo on a part time project, so please bear with me for
>> such basic questions (kind of also shows my lack of rails experience), here
>> is my situation:
>> Let’s say I am extending Agility Tutorial to also keep track of time spent
>> by various users on a story.
>> So story has a field called total_time_to_burn
>> And I have a model called “time” with a field “time_burned”
>> Relation ship between Story, Time and User is as follows:
>> Story
>> has_many :times
>>
>> Time
>> belongs_to :story
>> belongs_to :user
>>
>> User
>> has_many :times
>>
>> When user spends some time working on a story, she updates that info, so
>> user does following:
>> 1.      Goes to the story and enters time_burned and clicks add (I have
>> achieved this, similar to as suggested for adding task to the story but I
>> need to figure out how to default the user logged-in to be automatically
>> associated with the Time object created).
>>
>
> Adding :creator => true to the user field will make this happen.
>
>
> 2.      Total_time_to_burn field of the story should be reduced (deducted)
>> by the amount of time_burned entered by the user for the time model. (I need
>> to know how to achieve it?)
>>
>
> You'd want to do the calculation in an after_save callback on the Time
> model:
>
> class Time < ActiveRecord::Base
> ...
>  after_save :adjust_time_to_burn
>
>  def adjust_time_to_burn
>    self.story.update_attribute(:total_time_to_burn,
> story.total_time_to_burn - time_burned)
>  end
> ...
> end
>
> See http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html for
> more details.
>
> One note: 'Time' is a reserved constant in Ruby. Naming a model that may
> cause deeply bizarre things to happen when Rails tries to do date/time
> conversions.
>
> --Matt Jones
>
> --
> You received this message because you are subscribed to the Google Groups
> "Hobo Users" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<hobousers%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/hobousers?hl=en.
>
>


-- 
regards
abbasi

-- 
You received this message because you are subscribed to the Google Groups "Hobo 
Users" 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/hobousers?hl=en.

Reply via email to