OK - for those that come after me ... I solved it thus ...

The HOBO manual (currently pp386-7) says, with regard to TRANSITIONS:

The second argument is a hash with a single item: {from => to}
This transition can only be fired in the state or states given as
from, which can be either a symbol or an array of symbols. On
completion of this transition, the record will be in the state give as
to which can be one of:
A symbol – the name of the state
A proc – if the proc takes one argument it is called with the record,
if it takes none it is instance_eval ̳d on the record. Should return
the name of the state.
A string – evaluated as a Ruby expression with in the context of the
record.

A symbol is the normal way to do this - ie {:admitted => :discharged}

To use a proc, you have to do this:

Add a method to current class ...

  def remove_patient_location
    self.location_id = nil
    return :discharged
  end

and then call that in the transition method as a proc:

  lifecycle :state_field => :admission_status do

    state  :admitted
    state  :discharged ,  :default => true

    transition  :disharge_patient, { :admitted => proc
{ remove_patient_location } } ,
                :available_to => :all do
    end


  end

Gad that made my eyes water.

My question is - given that this is such a simple update - how do you
do that with a string (the third method mentioned in the manual)

The following doesn't work:

    transition  :disharge_patient, { :admitted => " self.location_id =
nil , :discharged"  } ,
                :available_to => :all do
    end


Any ideas?


DJ




On Apr 5, 12:18 pm, DJ <[email protected]> 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
>
> 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

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