Skip to content

Commit 2ac149d

Browse files
committed
Correct explanation of strong parameters
This change corrects a misunderstanding of the way required parameters are handled. Whilst there is an exception wrapper that maps ActionController::ParameterMissing to a 400 bad request, this is only used in logging. The current description implies that the exception is caught and a 400 Bad Request response is sent. This is not the case.
1 parent faca40d commit 2ac149d

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

guides/source/action_controller_overview.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,10 @@ which attributes to allow for mass update. This is a better security
198198
practice to help prevent accidentally allowing users to update sensitive
199199
model attributes.
200200

201-
In addition, parameters can be marked as required and will flow through a
202-
predefined raise/rescue flow that will result in a 400 Bad Request being
203-
returned if not all required parameters are passed in.
201+
In addition, parameters can be marked as required and an `ActionController::ParameterMissing`
202+
exception will be raised if not all required parameters are passed. If this
203+
is the case the log will show the request completing as a 400 Bad Request
204+
even though the exception is not caught.
204205

205206
```ruby
206207
class PeopleController < ActionController::Base
@@ -211,11 +212,11 @@ class PeopleController < ActionController::Base
211212
Person.create(params[:person])
212213
end
213214

214-
# This will pass with flying colors as long as there's a person key
215-
# in the parameters, otherwise it'll raise a
216-
# ActionController::ParameterMissing exception, which will get
217-
# caught by ActionController::Base and turned into a 400 Bad
218-
# Request error.
215+
# This will pass with flying colors as long as there's a person
216+
# key in the parameters, otherwise it'll raise an
217+
# ActionController::ParameterMissing exception.
218+
# In this case the log will show the request completing as a
219+
# 400 Bad Request.
219220
def update
220221
person = current_account.people.find(params[:id])
221222
person.update!(person_params)

0 commit comments

Comments
 (0)