the-trash/the_comments

ActionController::UnpermittedParameters - found unpermitted parameters: commentable_type, commentable_id

dept42 opened this issue · 4 comments

I was receiving this error, with a fresh install of 2.2.2 on rails 4.1.5:

ActionController::UnpermittedParameters - found unpermitted parameters: commentable_type, commentable_id:
  actionpack (4.1.5) lib/action_controller/metal/strong_parameters.rb:377:in `unpermitted_parameters!'
  actionpack (4.1.5) lib/action_controller/metal/strong_parameters.rb:270:in `permit'
  the_comments (2.2.2) app/controllers/concerns/controller.rb:168:in `comment_params'
  the_comments (2.2.2) app/controllers/concerns/controller.rb:113:in `create'

I was able to easily fix by adding this to my own comments_controller:

  def comment_params
    params
    .require(:comment)
    .permit(:title, :contacts, :raw_content, :parent_id, :commentable_type, :commentable_id)
    .merge(denormalized_fields)
    .merge(request_data_for_comment)
    .merge(tolerance_time: params[:tolerance_time].to_i)
    .merge(user: current_user, view_token: comments_view_token)
  end

..but I don't understand how it ever could have worked by default. Is this a bug, or is something wrong with my installation?

Hello!
You should to remove additional params here. Because :commentable_type, :commentable_id used into another place:

https://github.com/the-teacher/the_comments/blob/master/app/controllers/concerns/the_comments/controller.rb#L138

Right now I can't understend why you have this error. Try to install code from master version 2.3.0
For my projects gem works fine.

Btw, I worrking on version 3. You can learn new version in branch v3.0

In the view, have you edited @post

<%= render partial: 'the_comments/tree', locals: { commentable: @post, comments_tree: @comments } %>

?

out of date. sorry