Skip to content

pondpaun7z/administrate-field-aasm

Repository files navigation

Administrate::Field::Aasm

Gem Version

Custom Administrate Field for AASM gem.

DEMO

Try the demo

Installation

Add this line to your application's Gemfile:

gem 'administrate-field-aasm'

And then execute:

$ bundle

Add to your dashboard:

ATTRIBUTE_TYPES = [
  state: Field::Aasm
]

SHOW_PAGE_ATTRIBUTES = %i[
  ...
  state
  ...
]

Add to your routes.rb

resources :orders do
  member do
    put '/:event', to: 'orders#transit_state'
  end
end

Add to your controller

def transit_state
  if requested_resource.try("may_#{params[:event]}?".to_sym)
    requested_resource.try(params[:event].to_sym)
    requested_resource.save
    redirect_to admin_order_path(requested_resource), notice: "#{params[:event].humanize} successfully."
  else
    redirect_to admin_order_path(requested_resource), alert: "#{params[:event].humanize} fail."
  end
end

License

The gem is available as open source under the terms of the MIT License.