我的 Controller 中有以下内容:
respond_to :html, :except => :some_action
respond_to :json, :xml
如果您在浏览器中点击 :some_action
路由(使用 Chrome 测试),您会收到 406 Not Acceptable 响应。有没有办法在 Rails 中“捕获”这个并做其他事情(比如重定向)?
此外,我试图避免使用respond_to
的 block 形式。我只是好奇是否有办法处理这种情况。
最佳答案
有一些关于操作覆盖的内容:
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
关于ruby-on-rails-3 - Rails 3.1 respond_to :html with :except,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6853907/