On a Rails 7.1 app, I have the form below
<%= form_with model: @post do |form| %>
<%= form.text_area :body %>
<%= form.submit %>
<% end %>
And the related action.
def update
@post = Post.find(params[:id])
if @post.update(post_params)
...
end
end
private
def post_params
params.require(:post).permit(:body)
end
When I submit the form, the following parameters are sent to the controller.
Parameters: {"authenticity_token"=>"[FILTERED]", "post"=>{"body"=>""}, "commit"=>"Update Post", "id"=>"1"}
Is there a way to prevent Unpermitted parameter to be raised?
Unpermitted parameters: :_method, :authenticity_token, :button, :id. Context: { controller: PostsController, action: update, request: #ActionDispatch::Request:0x0000000110733988, params: {"_method"=>"patch", "authenticity_token"=>"[FILTERED]", "post"=>{"body"=>""}, "commit"=>"Update Post", "controller"=>"posts", "action"=>"update", "id"=>"1"} }
Am I missing something here?
There is config for unpermitted parameters
You can choose needed