cancanとdeviceを使ってログイン認証画面を作ろうとしています。
#ablity.rb
ruby
1if user && user.admin? 2 can :access, :rails_admin # grant access to rails_admin 3 can :manage, :all # allow superadmins to do anything 4 end 5# Define abilities for the passed in user here. For example: 6# 7# user ||= User.new # guest user (not logged in) 8# if user.admin? 9# can :manage, :all 10# else 11# can :read, :all 12# end 13# 14# The first argument to `can` is the action you are giving the user 15# permission to do. 16# If you pass :manage it will apply to every action. Other common actions 17# here are :read, :create, :update and :destroy. 18# 19# The second argument is the resource the user can perform the action on. 20# If you pass :all it will apply to every resource. Otherwise pass a Ruby 21# class of the resource. 22# 23# The third argument is an optional hash of conditions to further filter the 24# objects. 25# For example, here the user can only update published articles. 26# 27# can :update, Article, :published => true 28# 29# See the wiki for details: 30# https://github.com/CanCanCommunity/cancancan/wiki/Defining-Abilities 31user ||= User.new # guest user (not logged in) 32 if user.has_role?('admin') 33 can :manage, :all 34 end 35 end 36 end 37
登録したメールアドレスとパスワードを入力して認証させる方法を教えてください。
cancanを導入する前の時点で、ログイン操作は正常にできますか?
あなたの回答
tips
プレビュー