Rails 3.1 respond_to :html with :except
I have the following in my controller:
respond_to :html, :except => :some_action
respond_to :json, :xml
If you hit the :some_action
route in a browser (tested with Chrome), you get a 406 Not Acceptable response back. Is there a way to "catc开发者_如何学JAVAh" this in Rails and do something else (like a redirect)?
Additionally, I'm trying to avoid using the block form of respond_to
. I'm just curious if there is some way to handle this case.
Check this out: http://ryandaigle.com/articles/2009/8/6/what-s-new-in-edge-rails-cleaner-restful-controllers-w-respond_with
There's a bit about action overriding:
class UsersController < ApplicationController::Base
respond_to :html, :xml, :json
# Override html format since we want to redirect to a different page,
# not just serve back the new resource
def create
@user = User.create(params[:user])
respond_with(@user) do |format|
format.html { redirect_to users_path }
end
end
end
精彩评论