我发现下面的wiki页面上部分的答案:https://github.com/plataformatec/devise/wiki/How-To:-Make-Devise-work-with-other-formats-like-mobile,-iphone-and-ipad-(Rails-specific)
所以 - 在汇总(除了登记在这个问题解释MIME类型等):
在config /初始化/ devise.rb文件,取消对config.navigational_formats线替换为:
config.navigational_formats = [:"*/*", "*/*", :html, :test]
一个文件添加到初始化,并添加以下代码行:
ActionController::Responder.class_eval do
alias :to_test :to_html
end
我还需要重写一个设计方法,因为我的MIME类型实际上也响应html - 但我确实想看看它是否也响应:test。所以,再一次在初始化文件夹,添加包含下列文件:
module Devise
module Controllers
# Helpers used in both FailureApp and Devise controllers.
module SharedHelpers
protected
# Helper used by FailureApp and Devise controllers to retrieve proper formats.
def request_format
@request_format ||= if request.format.test?
:test
elsif request.format.respond_to?(:ref)
request.format.ref
elsif MIME_REFERENCES
request.format
elsif request.format # Rails < 3.0.4
request.format.to_sym
end
end
end
end
end
这可能是因为它本来吸尘器 - 而不是重写上面的方法 - 在覆盖方法监狱长,做的重定向到未经授权的网址 - 但我无法弄清楚,也不确定是否Devise(上游)不是更好的方法来覆盖方法。
关于第二个想法 - Devise SharedHelpers并非真的必要 - 您只需将您打算的respond_to:test,:html添加到您的设计控制器的顶部即可。这应该做到这一点。 – Joerg