Skip to content

Commit

Permalink
Update method docs to reflect the new 422 response on unsuccessful cases
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosantoniodasilva committed Jan 24, 2021
1 parent ca2ab74 commit b2dd0a6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -212,7 +212,8 @@ assertions on this behavior for your controllers.
def create
@widget = Widget.new(widget_params)
@widget.errors.add(:base, :invalid)
# `respond_with` will render the `new` template again.
# `respond_with` will render the `new` template again,
# and set the status to `422 Unprocessable Entity`.
respond_with @widget
end
```
Expand Down
9 changes: 5 additions & 4 deletions lib/action_controller/respond_with.rb
Expand Up @@ -95,7 +95,8 @@ def clear_respond_to
# i.e. its +show+ action.
# 2. If there are validation errors, the response
# renders a default action, which is <tt>:new</tt> for a
# +post+ request or <tt>:edit</tt> for +patch+ or +put+.
# +post+ request or <tt>:edit</tt> for +patch+ or +put+,
# and the status is set to <tt>422 Unprocessable Entity</tt>.
# Thus an example like this -
#
# respond_to :html, :xml
Expand All @@ -116,8 +117,8 @@ def clear_respond_to
# format.html { redirect_to(@user) }
# format.xml { render xml: @user }
# else
# format.html { render action: "new" }
# format.xml { render xml: @user }
# format.html { render action: "new", status: :unprocessable_entity }
# format.xml { render xml: @user, status: :unprocessable_entity }
# end
# end
# end
Expand Down Expand Up @@ -194,7 +195,7 @@ def clear_respond_to
# need to render a template which is outside of controller's path or you
# want to override the default http <tt>:status</tt> code, e.g.
#
# respond_with(resource, render: { template: 'path/to/template', status: 422 })
# respond_with(resource, render: { template: 'path/to/template', status: 418 })
def respond_with(*resources, &block)
if self.class.mimes_for_respond_to.empty?
raise "In order to use respond_with, first you need to declare the " \
Expand Down
4 changes: 2 additions & 2 deletions lib/action_controller/responder.rb
Expand Up @@ -49,7 +49,7 @@ module ActionController #:nodoc:
# format.html { redirect_to(@user) }
# format.xml { render xml: @user, status: :created, location: @user }
# else
# format.html { render action: "new" }
# format.html { render action: "new", status: :unprocessable_entity }
# format.xml { render xml: @user.errors, status: :unprocessable_entity }
# end
# end
Expand Down Expand Up @@ -113,7 +113,7 @@ module ActionController #:nodoc:
# if @task.save
# flash[:notice] = 'Task was successfully created.'
# else
# format.html { render "some_special_template" }
# format.html { render "some_special_template", status: :unprocessable_entity }
# end
# end
# end
Expand Down

0 comments on commit b2dd0a6

Please sign in to comment.