【发布时间】:2012-09-15 19:18:40
【问题描述】:
我正在覆盖 设备会话控制器...它可以工作(我可以使用 json 登录),但我无法让它重定向到另一个错误操作:
class Users::SessionsController < Devise::SessionsController
def create
resource = warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#no")
return invalid_login_attempt unless resource
sign_in(resource_name, resource)
#respond_with resource, :location => redirect_location(resource_name, resource)
respond_to do |format|
format.json { render :status => 200, :json => { :success => true, :auth_token => resource.authentication_token, :user => resource } }
end
end
def no
puts "NO!"
return render:json => {:success => false, :errors => alert}
end
end
我也试过了:
if resource.nil?
puts "NIL!"
end
我总是收到相同的默认设计 json 错误以响应错误的登录凭据:
{error: "You need to sign in or sign up before continuing."}
我做错了什么?
【问题讨论】:
-
您找到解决方案了吗?我遇到了同样的问题。
-
找到任何解决方案了吗?
-
您是否为#no 操作定义了路线?
标签: ruby-on-rails devise controller