新手試玩 rails_admin 快速建構後台。
版本:
gem 'cancancan'
gem "rolify"
gem 'rails', '~> 5.0.0.rc2'
gem 'pg'
gem "rack-pjax", :github => "afcapel/rack-pjax"
gem "remotipart", :github => "mshibuya/remotipart"
gem "devise"
gem 'rails_admin', git: 'https://github.com/sferik/rails_admin.git'
# rails_admin.rb
RailsAdmin.config do |config|
config.authorize_with :cancan, AdminAbility
end
# admin_ability.rb
class AdminAbility
include CanCan::Ability
def initialize(user)
if user.has_role?('admin')
can :read, :all
can :access, :rails_admin
can :dashboard
if user.has_role?('superadmin')
can :manage, :all
else
can :manage, [] # A
end
end