On April 5, 2011 08:55:51 am DJ wrote:
> Hi Henry
> 
> Goog lord, that is a lot easier - and is, of course, what I tried
> first - but without the self.save. Arg.
> 

Sorry, I forgot about that particular ruby quirk that a "self." is required to 
change attributes (it continuously bites me), but I didn't think it was needed 
on the save.  I looked at my code to see if I had a "save" in a transition, 
but could not find any because I always write a method that is closer to the 
customer's language (e.g. "free_room!").

I'm glad you have it working.
Henry


> Thanks
> 
> Final code simply reads:
> 
>     transition  :disharge_patient, { :admitted => :discharged  } ,
> 
>                 :available_to => :all do
> 
>       self.location_id = nil
>       self.save
>     end
> 
> Easy.
> 
> 
> 
> On Apr 5, 1:31 pm, Henry Baragar <[email protected]>
> 
> wrote:
> > On April 5, 2011 07:18:49 am DJ wrote:
> > > Having not got a reply to this, perhaps I should add something about
> > > what I already tried ... ?
> > > 
> > > My sense from the Hobo documentation is that the important thing is to
> > > keep model-related stuff in the model, so I assume that the changing
> > > the value of a field during a transition involves an assignment within
> > > a method in the model.rb file.
> > > 
> > > So ... I did an assignment to what I thought would be the instance
> > > variable of the current patient as so ...
> > > 
> > >     transition  :disharge_patient, { :admitted => :discharged },
> > > 
> > >                 :available_to => :all do
> > > 
> > >          @patient.location_id = nil
> > >     end
> > 
> > Two things:
> > The "do" blocks works on the current object (a patient in this case) so
> > you can call its methods directly, namely: "location_id = nil" (or
> > "location = nil").
> > The assignment works on on the object in memory:  you have to save the
> > object after making the assignment (i.e. "save")
> > Regards,
> > Henry
> > 
> > > but that doesn't work since it thinks location_id is a method ... and
> > > the console tells me @patient is not defined.
> > > 
> > > I've tried a few other things within the Lifecycle statement - but
> > > most of them crash, indicating that I'm a Ruby-Noobie.
> > > 
> > > Any help on this gratefully received. I'm a bit stuck on this.
> > > 
> > > Thanks
> > > 
> > > DJ
> > > 
> > > On Apr 4, 12:46 am, DJ <[email protected]> wrote:
> > > > Apologies if this is ridiculously straightforward - my learning-curve
> > > > is near vertical and I've got a bit lost on the Hobo/Rails cliff-face
> > > > (but enjoying it). Thanks in advance to any suggestions.
> > > > 
> > > > I have a very simple patient database with a lifecycle which holds
> > > > whether the patient is admitted or discharged -  this is working
> > > > wonderfully using TablePlus and <transition-buttons/>.
> > > > 
> > > > However, I want to  'blank-out' (set to nil probably) the location
> > > > when a patient is discharged.
> > > > 
> > > > My question is how best to do this.
> > > > 
> > > > Any help gratefully received. Many thanks
> > > > 
> > > > DJ
> > > > 
> > > > __________________________
> > > > 
> > > > Relevant code in patient.rb is as follows:
> > > > 
> > > > class Patient < ActiveRecord::Base
> > > > 
> > > >   hobo_model # Don't put anything above this
> > > > 
> > > >   fields do
> > > >     first_name                     :string
> > > >     last_name                      :string
> > > >    # etc - field-list cut for clarity ...
> > > >     timestamps
> > > >   end
> > > > 
> > > >   belongs_to :location
> > > >  # etc - other relationships cut for clarity
> > > > 
> > > >   lifecycle :state_field => :admission_status do
> > > > 
> > > >     state  :admitted
> > > >     state  :discharged ,  :default => true
> > > > 
> > > >     transition  :admit_patient, { :discharged => :admitted } ,
> > > > :params => [ :location ] ,
> > > >                 :available_to => :all do
> > > > 
> > > >     end
> > > > 
> > > >     transition  :disharge_patient, { :admitted => :discharged },
> > > >                 :available_to => :all do
> > > > 
> > > >     end
> > > > 
> > > >   end
> > 
> > --
> > Henry Baragar
> > Instantiated Software

-- 
Henry Baragar
Instantiated Software

-- 
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