The classic example is a transfer between two accounts:
def transfer(from, to, amount)It is vital that the above method (example provided by Tate and Hibbs) does not fail after the debit. In Rails the
from.debit(amount)
to.credit(amount)
end
transaction
method help to prevent 'digital accidents' as follows:def transfer(from, to, amount)
Account.transaction do
from.debit(amount)
to.credit(amount)
end
end
transaction
is itself a method built into Rail's Active Record that helps to maintain the integrity of transactions. Which brings me to 'care'. ...There are several blog posts here since you reach a stage in your career when the hard fought lessons of yesteryear have to be faced again but this time like after dinner wind.
There are many possible
care transactions
that arise.Many have a specific context and frequently these are conjoined:
- timing
- relationships - trust
- responsibility - transfer
- care environment
- record (paper, electronic)
care transaction
consider these:def transfer(from, to, care_plan)Wherever, whenever, whatever and whoever your transactions involve, take care of them and remember in health and social care (esp.) outcomes add up.
Care.transaction do
from.hospital(care_plan)
to.community(care_plan)
end
end
def transfer(from, to, day_care)
Care.transaction do
from.home(day_care)
to.day_center(day_care)
end
end
Don't forget to look after the however: the information, the knowledge, the promises ....
def transfer(from, to, promise_plan_of_action)Reference: Bruce Tate, Curt Hibbs (2006) Ruby on Rails: Up and Running, O'Reilly, p.35.
Care.transaction do
from.nurse(promise_plan_of_action)
to.carer(promise_plan_of_action)
end
end