Tuesday 15 April 2014

Rails 4 with CanCan: unknown attribute error after including load_and_authorize_resource -


I am working in Rail 4 and have received Cancun to work well with the instructions, Em> except for a use case which I think may be relatively common.

I have a comment model, which is is_im: comments, via :: for nested comments. All this is working fine, as long as I add load_and_authorize_resource to my comment controller, I think this attribute can be replaced by an optional : parent_comment_id attribute via strong parameters There may be a problem with the hidden field to send.

I have allowed this feature through strong standards:

  def comment on the top (note.). Pyremit (: content, parent_comment_id,: post_id, : Comment_id, user_id) end   

Because I can create an association if any : parent_comment_id is included:

  if Comment_params [: parent_comment_id]! Answer = Nil. ({: Parent_comment_id = & gt; Comment_user [: parent_comment_id] ,: comment_id = & gt; @ comment.id}) end   

But once i load_and_authorize_resource Add, then I get an unknown attribute error for : parent_comment_id . What am I missing?

The solution to my sleep came to me to solve this problem: What I did: / P>

There was no problem generating the only reason comment_params because I was leaving the extra : parent_comment_id parameter, like this: <

comment_params Although the method was not such a cleanliness, therefore, problem On the basis of per-controller, Cancans would have been messy to add hygiene, so I did what I should have done together and instead of going inside : parent_comment_id , : comment < / Code>, I used hidden_field_tag ​​ to pass it out to : comment and through plain, old parameters Accessed.

I hope it helps someone else who makes such a mistake!

No comments:

Post a Comment