ruby on rails - How do I define instance abilities in cancan without defining class abilities? -
how define instance abilities in cancan without defining class abilities?
i want allow :manage
action particular course
instances, not course
class.
# ability.rb can :manage, course of study |course| # check if user helper course of study courserole.get_role(user, course) == "helper" end
this works fine instance variables:
# some_view.rb can? :manage, @course # checks instance see if :manage allowed
but if this:
# some_view.rb can? :manage, course of study
it returns true, bad.
some context:
class user < activerecord::base has_many :course_roles has_many :courses, :through => :course_roles ... class courseroles < activerecord::base belongs_to :user belongs_to :course ... class courses < activerecord::base has_many :course_roles has_many :users, :through => :course_roles
instead of can? :manage, course
, can utilize can? :manage, course.new
, sure new course of study objects fail block passed in ability.rb
ruby-on-rails ruby cancan
No comments:
Post a Comment