1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| # Devise 中增加 role 身份 1. rails generate migration add_admin_to_users_table 2. 修改 db/migrate/[date]_add_admin_to_users_table.rb 為
class AddAdminToUsersTable < ActiveRecord::Migration def self.up add_column :users, :admin, :boolean, :default => false end def self.down remove_column :users, :admin end end
3. rake db:migrate 4. 建立 config/initializer/rails_admin.rb 內容為
RailsAdmin.config do |config| config.authorize_with do redirect_to '/' unless current_user.try(:admin?) end end
|