Rails devise Sessions Controller

13,088

Create your Sessions Controller with rails g controller MySessions. Then inside of your controller change it from inheriting from ApplicationController to the Devise Controller like so:

class MySessionsController < Devise::SessionsController

#your session logic here

end

Any of the logic within that controller that you want to override you can override by calling that method and inserting your own logic. For the list of what's in that controller, you can view the code on their Github page. If you do not wish to override their methods you can either leave them out, or just call super.

def new
  super
end
Share:
13,088
Kevin
Author by

Kevin

Updated on June 04, 2022

Comments

  • Kevin
    Kevin almost 2 years

    In devise, many of the pages that teach how to accomplish certain things require editing a sessions controller. I set up devise using this https://github.com/fortuity/rails3-subdomain-devise/wiki/Tutorial-(Walkthrough) It didn't go over making a sessions controller. How do I make one. (If it's really easy i'm sorry, just give me the few simple steps)

  • umezo
    umezo over 11 years
    Thanks for the helpful feedback @janders. BTW, is there a reason why it's MySessions instead of Sessions as in the source code? Is that a typo, or does it not matter that it's different?
  • janders223
    janders223 over 11 years
    The name of your controller does not matter, so long as it inherits from Devise::SessionsController.
  • umezo
    umezo over 11 years
    ah, just realized it's inheriting from Devise::SessionsController and not simply DeviseController. That makes sense, thanks.
  • Yetanotherjosh
    Yetanotherjosh about 11 years
    Actually the name of the controller DOES matter. There are numerous places inside Devise which compare the current value of controller_name to "sessions". Also, the i18n keys it uses are based off the controller name, etc. You should call your subclass just SesssionsController