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.
- On the list view, the current state with coloration will be displayed. No events will be displayed here.
- On the Edit view, there will be the event buttons as well as the current state. The enum view has been removed.
- After clicking a state machine action, the user is redirected back to the show view. This allows for state-dependent editing.
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
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
**NOTE: this is now required **
rails_admin do
list do
field :state, :state
...
end
...
state({
events: {reject: 'btn-warning'}
states: {on_moderation: 'btn-warning'}
})
end
Just as usual for state_machine, see:
http://rdoc.info/github/pluginaweek/state_machine/master/StateMachine/Integrations/Mongoid
http://rdoc.info/github/pluginaweek/state_machine/master/StateMachine/Integrations/ActiveRecord
For namespaced models use "/", just as usual: "Blog::Post" is "blog/post"
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request