This project is archived and is in readonly mode.
respond_with fails silently on missing mimetype
Reported by Don Werve | March 2nd, 2010 @ 05:58 AM | in 3.0.2
Happens on a 'PUT /things/1' request with the below code; haven't tried with POST or any other verbs at the moment.
class ThingsController < ApplicationController
respond_to :html, :xml, :json
def update
@thing = Thing.find(params[:id])
@thing.update_attributes(params)
@thing.save!
respond_with(@thing)
end
end
If I execute a PUT request with anything but the default format, the above code fails silently; nothing in the logs, nothing fired back to the user. If I replace the 'respond_with' block with an older 'respond_to do |format|' style block, or manually add the mimetypes in via a block passed to respond_with, then things work again.
By 'anything but the default format', I mean that if I append a format to the URL, things fail silently. This happens with '.xml', '.json', '.totallyinvalidformat', etc.
Comments and changes to this ticket
-
José Valim March 3rd, 2010 @ 08:39 AM
- Assigned user set to José Valim
- Milestone cleared.
Could you please provide a failing test case?
-
Jeremy Kemper March 3rd, 2010 @ 04:11 PM
- State changed from new to open
-
José Valim March 13th, 2010 @ 09:44 AM
I cannot reproduce. Can you tell us what block you were passing to respond_with or respond_to which made this work?
Notice that in respond_with, PUT requests for XML and JSON formats returns a "head :ok" in case of success. This means that you won't get anything back, except a "200 OK" status in case of success. In cases of failure, it should render some content, but since you are calling @thing.save!, if the resource is invalid it will raise an exception and you in fact won't see the error message, but probably get a 500 error.
For invalid formats, your browser is returning a 406 Not Acceptable status, which also, does not give you anything back. Though that should probably return a 404 for html requests.
-
José Valim March 26th, 2010 @ 11:45 AM
- State changed from open to invalid
Closing. If you have any information to reproduce it on master, please let me know.
-
Nikolay Belous July 23rd, 2010 @ 01:36 PM
- Importance changed from to High
class UsersController < ApplicationController
def create #POST
@user = User.first respond_with(@user) [#200](/projects/8994/tickets/200 "Ticket #200") OK, returns data
end
def show #GET: returns data
@user = User.first respond_with(@user) [#200](/projects/8994/tickets/200 "Ticket #200") OK, returns data
end
def update #PUT: no data
@user = User.first respond_with(@user) [#200](/projects/8994/tickets/200 "Ticket #200") OK, no data
end
def destroy #DELETE: no data
@user = User.first respond_with(@user) [#200](/projects/8994/tickets/200 "Ticket #200") OK, no data
end
end
I think this is very strange.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>