Skip to content

Association Extension

Mike Nelson edited this page Jan 29, 2020 · 4 revisions

The Subroutine::AssociationFields module provides an interface for loading ActiveRecord instances easily.

class UserUpdateOp < ::Subroutine::Op
  include ::Subroutine::AssociationFields

  association :user

  with_options groups: "update" do
    string :first_name 
    string :last_name
  end

  protected

  def perform
    user.update_attributes(update_params)
  end
end
class RecordTouchOp < ::Subroutine::Op
  include ::Subroutine::AssociationFields

  association :record, polymorphic: true

  protected

  def perform
    record.touch
  end
end
Clone this wiki locally