0

I am new in rails and I am doing one project which has this code

 aasm_column :status
  aasm do
    state :unregistered, initial: true
    state :pending, enter: :enter_pending_state
    state :activated, enter: :enter_activated_state
    state :disabled

    event :register do
      transitions from: :unregistered, to: :pending, guard: :valid?
    end

    event :activate do
      transitions from: [ :unregistered, :pending ], to: :activated
      transitions from: :pending, to: :activated, guard: :valid?
    end

    event :disable do
      transitions from: [ :pending, :activated ], to: :disabled, guard: :valid?
    end

    event :enable do
      transitions from: :disabled, to: :activated, guard: Proc.new { |u| u.activation_code.blank? && u.valid? }
      transitions from: :disabled, to: :pending, guard: Proc.new { |u| !u.activation_code.blank? && u.valid? }
    end
  end

before_create :enter_pending_state, if: Proc.new{|u|  u.pending? }

what does aasm_column means and what is the banalities to do this

Harman
  • 1,703
  • 5
  • 22
  • 40
  • "aasm" probably stands for "acts_as_state_machine" which is a gem to provide "finite state machine" functionality to objects. – Max Williams Apr 18 '16 at 11:14
  • take a look https://github.com/aasm/aasm – dp7 Apr 18 '16 at 11:14
  • As an aside, if you are learning Rails then trying to take over another existing project is **the worst possible way to learn about Rails that there is**. You need to learn it from the bottom up first or you will be completely lost and bewildered. – Max Williams Apr 18 '16 at 11:16
  • I read it but didn't understand about it, How it work or why we implement it? – Harman Apr 18 '16 at 11:31

1 Answers1

0

it is use for 'aasm' gem it your case aasm_column :status is override the default column of aasm gem that col name is 'state'

In this case we are using default column (aasm_state) for storing current state. But you easily override this behaviour inside aasm block.

MD Shahid Khan
  • 670
  • 4
  • 5