1
cancan, inherited_resources 및 단일 테이블 상속을 함께 사용하려면 어떻게해야합니까? 나는 사람을 만들기 위해 사용자로하려고하면CanCan, InheritedResources 및 STI
class Contact < ActiveRecord::Base; end
class Person < Contact; end
class Company < Contact; end
class Ability
include CanCan::Ability
def initialize(user)
user ||= User.new # in case of guest
can :read, Contact # User can read People and Companies
can :create, Person # User can create Person only
can :manage, :all if user.has_role? :admin
end
end
class ContactsController < InheritedResources::Base
load_and_authorize_resource
def new
@contact = contact_sti.new
end
private
def clazz
self.params[:contact_type].nil? ? "contact" : self.params[:contact_type]
end
def contact_sti
clazz.camelize.constantize
end
end
내가 캉캉 :: AccessDenied를 얻을 : 나는 코드와 유사한이 예제를 가지고있다. InheritedResources는 다음과 같이 Contact를 사용하기 때문입니다 : resource_class.
class ContactsController < InheritedResources::Base
alias :resource_class :contact_sti
end
: