Created
November 13, 2012 22:42
-
-
Save kagemusha/4068935 to your computer and use it in GitHub Desktop.
Override Devise Controllers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
c. Devise 2.1.2 | |
ref: https://github.com/plataformatec/devise/issues/1561 | |
E.g. you may want to send back json instead of html on login, etc. | |
Steps: | |
1. Override the controller (put in the controllers dir) | |
class SessionsController < Devise::SessionsController | |
2. Specify route in your route.rb file | |
YourApp::Application.routes.draw do | |
... | |
devise_for :users, :controllers => | |
{:sessions => 'sessions', | |
:registrations=>"registrations", | |
:passwords=>"passwords"} | |
Example overridden controller | |
class PasswordsController < Devise::PasswordsController | |
def create | |
#same as in parent | |
self.resource = resource_class.send_reset_password_instructions(resource_params) | |
#send json instead of html | |
if successfully_sent?(resource) | |
render :json=>{:success=>true} | |
else | |
render :json=>{:success=>false} | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment