Set an Attribute within an Action

I have a Resource that has an Attribute called type that is an enum.

I’m creating separate create Actions for each type and so want to set the type in the action itself since we know it.

    attribute :type, :atom do
      constraints one_of: [:paragraph, :image, :table, :citation]
      allow_nil? false
    end
    create :create_paragraph do
      argument :order, :integer, allow_nil?: false
      argument :body, :string, allow_nil?: false
    end

I want to set the Attribute type to :paragraph

You can definitely do change set_attribute(:type, :paragraph).

1 Like

Thank you!

For completeness this is what my action looks like in working condition:

    create :create_paragraph do
      argument :order, :integer, allow_nil?: false
      argument :body, :string, allow_nil?: false

      change set_attribute(:order, arg(:order))
      change set_attribute(:type, :paragraph)
    end
1 Like