Ruby on Rails 5 - 204 No Content - Why this change makes sense for you?
Note: This is a change that is present in the latest Rails version 5. Versions before the 5 will throw an error "MissingTemplate" exception.
In Ruby on Rails 5, there is a change that is particularly important. Rails server issues a HTTP code of 204 No Content when you request a POST method without a template but the action for the same is present. This happens only when the HTTP Verb is POST and it doesn't happen for GET requests.
This is the sample code for the action which will be called as POST:
def create @user = User.new(params[:user]) end
So how does this help you?
- GET via browser will throw an error. This is because Rails assumes that you have to have a template for showing some content to the user.
- Your html page after the POST request will be still the same and the page won't transition to a new page. This means that it will look like nothing has been done by the server and the user might be confused if its a form POST.
You can also follow me at Twitter, Facebook, LinkedIn and Website.