Skip to content

Instantly share code, notes, and snippets.

@kagemusha
Created November 13, 2012 22:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kagemusha/4068935 to your computer and use it in GitHub Desktop.
Save kagemusha/4068935 to your computer and use it in GitHub Desktop.
Override Devise Controllers
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