Rails アプリケーションで Cancan を Devise と連携させようとしています。ここの指示に従ってセットアップしようとしました:
次のエラーが発生しているため、行き詰まっています。
Users::RegistrationsController# の ArgumentError #新しい引数の数が間違っています (1 に対して 2)
app/models/ability.rb:7:in initialize'
app/controllers/users/registrations_controller.rb:6:in
check_permissions '
私のability.rbは次のようになります。
class Ability
include CanCan::Ability
def initialize(user)
user ||= User.new # guest user
if user.role? :super_admin
can :manage, :all
elsif user.role? :admin
can :manage, :all
elsif user.role? :user
can :read, :all
# manage products, assets he owns
can :manage, Product do |product|
product.try(:owner) == user
end
can :manage, Asset do |asset|
asset.assetable.try(:owner) == user
end
end
end
end
私の登録コントローラーの読み取り:
class Users::RegistrationsController < Devise::RegistrationsController
before_filter :check_permissions, :only => [:new, :create, :cancel]
skip_before_filter :require_no_authentication
def check_permissions
authorize! :create, resource
end
end
これは、サインアップ ページでのみ発生します。アプリ内の他のすべてのページは正常に機能しています。