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!!
Did you do the step recommended by Jeff Poulton in comment #4? The
:recalloption 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 => :failuremust 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.