Mike
Mike

Reputation: 1684

Rails 3 Devise Ajax error messages

So Im using this app, devise ajax login, to do ajax login.

Right now when the user logs in it is handled by the sessions controller which returns either a 401 or returns a success

class SessionsController < Devise::SessionsController

def create
  resource = warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#failure")
 sign_in(resource_name, resource)
 return render :json => {:success => true, :content => render_to_string(:layout =>  false, :partial => 'sessions/manager')}
end

def failure
  return render:json => {:success => false, :errors => ["Login failed."]}
 end
end

Is there a way to use ajax to insert flash/devise error messages for why the user failed login?

Upvotes: 1

Views: 1603

Answers (1)

Ashitaka
Ashitaka

Reputation: 19203

I don't really get your question. Could you clarify it a little bit? It's just that you are already dealing well with the success/failure of your login and returning a message accordingly.

Was it something like this you were looking for?

return render:json => {:success => false, :errors => [t("devise.failure.invalid")]}

Upvotes: 1

Related Questions