added strong params to comments_controller to prevent users from editing attributes which are not intended to be edited, also created specs to test this behaviour

This commit is contained in:
Janis4411
2022-08-04 17:16:54 +02:00
committed by Sebastian Serth
parent b98c37ae64
commit 4615a49e62
3 changed files with 48 additions and 2 deletions

View File

@ -55,7 +55,7 @@ class CommentsController < ApplicationController
# PATCH/PUT /comments/1.json
def update
if @comment.update(comment_params_without_request_id)
if @comment.update(comment_params_for_update)
render :show, status: :ok, location: @comment
else
render json: @comment.errors, status: :unprocessable_entity
@ -77,6 +77,10 @@ class CommentsController < ApplicationController
@comment = Comment.find(params[:id])
end
def comment_params_for_update
params.require(:comment).permit(:text)
end
def comment_params_without_request_id
comment_params.except :request_id
end