This project is archived and is in readonly mode.

#5096 ✓stale
Paul Campbell

Setting respond_to in application_controller creates mysterious 406 when respond_to is called in other controllers

Reported by Paul Campbell | July 12th, 2010 @ 05:05 PM

I created a before_filter in application_controller:

def set_return_to
  respond_to do |format|
    format.html { session[:return_to] = url_for(params) }
  end
end

But any subsequent calls to respond_to within other controllers cause a very silent:

def index
  @comments = Comment.all
  respond_to do |format|
    format.html
    format.js
  end
end

GET /comments/?format=js

406 Not Acceptable

If I add this in application_controller.rb:

def set_return_to
  respond_to do |format|
    format.html { session[:return_to] = url_for(params) }
    format.any { return }
  end
end

...things work just fine.

I'm pretty sure in Rails 2.3 you could specify only one type to respond to in application_controller and that it wouldn't limit the response types elsewhere.

Regardless, it was the mysterious "406 Not Acceptable" that had me thinking this was a bug. Perhaps even a message to say where I was limiting the accept types.

—P

Comments and changes to this ticket

  • Paul Campbell

    Paul Campbell July 12th, 2010 @ 05:13 PM

    Sample app with this functionality here:

    http://github.com/hypertiny/testy

    rails server

    curl localhost:3000/flowers/?format=xml

  • rails

    rails February 26th, 2011 @ 12:00 AM

    • State changed from “new” to “open”

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

  • rails

    rails February 26th, 2011 @ 12:00 AM

    • State changed from “open” to “stale”

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>

People watching this ticket

Pages