You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Allows easily sending state_machine events to a model from Rails Admin, including support for
ActiveRecord \ Mongoid and custom state field name and multiple state machines per model.
Screenshot
Installing
Add this line to your application's Gemfile:
gem 'rails_admin_state'
And then execute:
$ bundle
Or install it yourself as:
$ gem install rails_admin_state
Usage
Add the state action:
RailsAdmin.config do |config|
config.actions do
......
state
end
end
Mark the field you need display as state:
rails_admin do
list do
field :state, :state
...
end
edit do
field :state, :state
...
end
...
end
States and event button/label custom classes:
rails_admin do
list do
field :state, :state
...
end
...
state({
events: {dead: 'btn-danger', drain: 'btn-warning', alive: 'btn-success'},
states: {dead: 'label-important', drain: 'label-warning', alive: 'label-success'}
disable: [:dead] # disable some events so they are not shown.
})
end
Some classes are preset by default (published, deleted, etc)
CanCan integration
cannot :manage, Recipes::Recipe
can :read, Recipes::Recipe
can :state, Recipes::Recipe # required to do any transitions
can :all_events, Recipes::Recipe