I'm working in Rails 4 and have gotten CanCan to work well with instructions from this issue, except for one use case that I think might be relatively common.
I have a Comment
model, which has_many :comments, through: :replies
for nested comments. All of this is working well, until I add load_and_authorize_resource
to my comments controller. The problem seems to stem from a hidden field sending an optional :parent_comment_id
attribute to my create action.
I've permitted this attribute via strong parameters:
def comment_params
params.require(:comment).permit(:content, :parent_comment_id, :post_id, :comment_id, :user_id)
end
So that I can create the association if a :parent_comment_id
is included:
if comment_params[:parent_comment_id] != nil
Reply.create({:parent_comment_id => comment_params[:parent_comment_id], :comment_id => @comment.id})
end
But once I add load_and_authorize_resource
, I get an unknown attribute error for :parent_comment_id
. What am I missing?