Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

respond_with fails silently on missing mimetype

#4088

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.

Reported by Don Werve · March 2nd, 2010 @ 05:58 AM

State: invalid
Milestone: 3.0.2
Assigned to: José Valim José Valim
Importance: High

Activity

  1. José Valim
    José Valim
    • Assigned user set to José Valim
    • Milestone cleared.

    Could you please provide a failing test case?

    March 3rd, 2010 @ 08:39 AM

  2. Jeremy Kemper
    Jeremy Kemper
    • State changed from new to open

    March 3rd, 2010 @ 04:11 PM

  3. José Valim
    José Valim

    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.

    March 13th, 2010 @ 09:44 AM

  4. José Valim
    José Valim
    • State changed from open to invalid

    Closing. If you have any information to reproduce it on master, please let me know.

    March 26th, 2010 @ 11:45 AM

  5. Nikolay Belous
    Nikolay Belous
    • 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.

    July 23rd, 2010 @ 01:36 PM

  6. Jeremy Kemper
  7. bingbing