Rails 3 AJAX:常量名称错误
我正在尝试使用 Devise 进行 Ajax 登录,如下所述: http://jessehowarth.com/2011/04/27/ajax-login-with-devise#comment-5(请参阅 jBeasley 的评论)。
我的控制器正在尝试返回,
class Users::SessionsController < Devise::SessionsController
def failure
render :json => {:success => false, :errors => ["Login failed."]}
end
end
这会导致此错误:
NameError (wrong constant name ["{\"success\":false,\"errors\":[\"Login failed.\"]}"]Controller):
并且 Firebug 显示 [500 内部服务器错误]。
我该如何解决这个问题?我正在运行 Rails 3.1 并设计 1.4.5。
谢谢!!
I am trying to do Ajax login with Devise, as explained here: http://jessehowarth.com/2011/04/27/ajax-login-with-devise#comment-5 (see comment from jBeasley).
My controller is attempting to return
class Users::SessionsController < Devise::SessionsController
def failure
render :json => {:success => false, :errors => ["Login failed."]}
end
end
which results in this error:
NameError (wrong constant name ["{\"success\":false,\"errors\":[\"Login failed.\"]}"]Controller):
and Firebug showing [500 Internal Server Error].
How can I fix this? I am running Rails 3.1 and devise 1.4.5.
Thanks!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否执行了 Jeff Poulton 在评论 #4 中推荐的步骤? 1.4.5 中的
:recall
选项看起来与旧版本完全不兼容。现在,它要求您发送控制器,而在本教程中,您遵循的只是发送操作(旧方式)。在你的情况下,
:recall => :failure
必须更改为:recall => Devise 1.4.5 中的“users/sessions#failure”
。这是因为确定故障操作的控制器的方式所致。在旧版本中,它只是从参数中提取。
在 1.4.5 中,它需要一个以路由样式指定控制器和操作的字符串:
看起来您的应用实际上是将选项的 JSON 化哈希传递给
recall_app
,其中缺少'#' 不会被拆分,整个字符串会连接到“Controller”以尝试确定故障控制器的类。Did you do the step recommended by Jeff Poulton in comment #4? The
:recall
option in 1.4.5 looks to be completely incompatible to older versions. It now requires you send the controller, whereas in the tutorial you're following he just sends the action (the old way).In your case,
:recall => :failure
must be changed to:recall => "users/sessions#failure"
in Devise 1.4.5.This is because of the way the controller for the failure action is determined. In older versions, it was simply pulled from the params.
In 1.4.5, it expects a string specifying the controller and action, in the style of routes:
It would seem as though your app is actually passing the JSONified hash of options to
recall_app
, which, lacking a '#', isn't being split, and the entire string is concatenated to "Controller" to attempt to ascertain the failure controller's class.中的退货。
您错过了“这有什么影响吗?”
You are missing the return in
Does that make a difference?