I have a TakeAction model that looks like this:
class TakeAction < ActiveRecord::Base
belongs_to :user
has_many :take_action_notes
attr_protected :user_id
end
and the TakeActionNote model, which looks like this:
class TakeActionNote < ActiveRecord::Base
belongs_to :take_action
validates_presence_of :note
end
Using CanCan, I am trying to allow the user who owns take_action to create and delete (delete) notes.
I tried to determine abilities with such a block.
can :manage, TakeActionNote do |action, note|
note.take_action.user.id == user.id
end
I can add notes to take_action without any problems, but when I try to destroy it, I get:
NoMethodError in action notesController # 33 undefined `take_action 'method for nil: NilClass
Is there something I am missing or something is wrong? Any help is appreciated. Thank!
source
share