rails_adminとcancancancancancanをインストールしましたが、adminが付与されていないユーザーでも、直接urlを入れると管理者ページに入れますが、どこがよくないのか分かりません。どなたかご教授ください。
RUBU
1RailsAdmin.config do |config| 2 3 ### Popular gems integration 4 5 ## == Devise == 6 7 config.authenticate_with do 8 warden.authenticate! scope: :user 9 end 10 config.current_user_method(&:current_user) 11 12 ## == Cancan == 13 config.authorize_with :cancan 14 15 ## == Pundit == 16 # config.authorize_with :pundit 17 18 config.actions do 19 dashboard # mandatory 20 index # mandatory 21 new 22 export 23 bulk_delete 24 show 25 edit 26 delete 27 show_in_app 28 29 end 30end 31
RUBY
1# frozen_string_literal: true 2 3class Ability 4 include CanCan::Ability 5 6 def initialize(user) 7 if user.try(:admin?) 8 can :access, :rails_admin 9 can :manage, :all 10 end
RUBY
1class AddColumnToUsers < ActiveRecord::Migration[5.2] 2 def change 3 add_column :users, :admin, :boolean, default: false 4 end 5end 6
DBでは、
id|user_name|password_digest|email|created_at|updated_at|imagename|point|admin
39|山本 けんいち|$2a$12$3ahhM/ihmgkJfvvnNMy0qucw1XSzzvm99MuBcJF2IfezIgfs4u9sq|ii@ii|2019-12-20 22:00:06.490327|2019-12-20 22:00:06.490327|default_user.jpg|未評価|0
という感じでadminは、0とでます。
あなたの回答
tips
プレビュー