Approach to triggering plutus entry creation

92 views
Skip to first unread message

Kevin Ross

unread,
Apr 17, 2015, 12:40:34 PM4/17/15
to plutu...@googlegroups.com
We have invoice, credit_note, payment models etc in our application.  

Is there a best practice, pros/cons of approaches to when you create your plutus entries?  Such as using the #after_create callback?  What have you found that works best?

mbulat

unread,
Apr 17, 2015, 2:03:15 PM4/17/15
to plutu...@googlegroups.com
Yes, that's what we do, though you want to be careful about the callback ordering. If you want the whole transaction to rollback if there is an error when adding any records to plutus, you'll want to use after_create. In some situations you may choose to ensure the record is saved and committed even if the plutus entry fails, in which case you'd want to use `after_commit on:create`

Another best practice we've found is to move the code into an ActiveSupport::Concern. So for our invoice class, we have an `include Receivable` and the receivable module looks something like this:

module Receivable
  extend ActiveSupport::Concern

  included do
    after_create :create_receivable_entry
  end

  def create_receivable_entry
    ...

This makes it easy to share the code among classes, and just an easy place to look for Plutus code in general
Reply all
Reply to author
Forward
0 new messages