Code Monkey home page Code Monkey logo

rails_admin_aasm's Introduction

Rails Admin State Machine

Properly manage AASM states from rails_admin

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.

Based on https://github.com/rs-pro/rails_admin_state. Since state_machine currently is not maintained, I turn to AASM https://github.com/aasm/aasm.

Installing

Add this line to your application's Gemfile:

#please use `0.1.1` if rails_admin <= `0.8.1`
gem 'rails_admin_aasm'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rails_admin_aasm

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

i18n (state and event names):

Events:

activerecord:
    events:
      product_order:
        pay: 支付
        refund: 同意退款
        reject_refund: 拒绝退款

State:

product_order:
    status/unpaid: 未支付

notice the state must combine with /, see: aasm/aasm#38

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

rails_admin_aasm's People

Contributors

zcpdog avatar max-konin avatar eniwito avatar ruslan-volyanyk avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.