2015年2月9日月曜日

Rails: devise install on rails_admin

■ devise user add

$ rails g devise:install
$ vim ../config/environments/development.rb
   config.action_mailer.default_url_options = { host: 'hhoshina.info', port: 3000 }  ← add
   end

$ rails g devise user
$ rake db:migrate

■new user add ( on rails_admin website )




■  add admin column to user

  $ rails g migration AddAdminToUser user
  $ vim 20150209134227_add_admin_to_user.rb
   -----
  1 class AddAdminToUser < ActiveRecord::Migration
  2   def change
  3     add_column :users, :admin, :boolean      <--- Change                                  
  4   end
  5 end
  -----

■ admin flag add ( on rails_admin website)

■ cancan config
 $ rails g cancan:ability
 $ vim model/ability.rb
  --------
  1 class Ability                                                                
  2     include CanCan::Ability
  3
  4     def initialize(user)
  5         if user && user.admin?
  6             can :access, :rails_admin
  7             can :manage, :all
  8         end
  9     end
 10 end
 --------

■rails_admin config
 $ vim initializers/rails_admin.rb

 12 ## == Devise ==
 13    config.authenticate_with do |controller|
 14     warden.authenticate! scope: :user
 15    end
 16    config.current_user_method(&:current_user)
 17 
 18   ## == Cancan ==
 19    config.authorize_with :cancan






0 件のコメント:

コメントを投稿

fd-find

 $ sudo apt install fd-find $ fdfind 石