我刚接触Ruby on Rails,所以可能我做错了什么…
在一个控制器(用户)中,我有一个“before_filter”,它调用applicationcontroller类中的“authenticate”方法。
用户控制器可以通过HTML或XML访问
respond_to do |format|
format.html
format.xml
end
问题是当过滤器不通过时,authenticate方法总是显示HTML页面…
我有两个文件authentication\u failed.html.erb和authentication\u failed.xml.erb。
在控制器中,“验证失败”方法如下:
def authentication_failed
respond_to do |format|
format
format.xml
end
end
authenticate方法(过滤器调用的方法)具有以下代码:
if !(authenticated) then
redirect_to authentication_failed_path
end
如果身份验证无法用XML而不是HTML页响应,我该怎么办?