Rails devise Sessions Controller
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
Kevin
Updated on June 04, 2022Comments
-
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 over 11 yearsThanks for the helpful feedback @janders. BTW, is there a reason why it's
MySessions
instead ofSessions
as in the source code? Is that a typo, or does it not matter that it's different? -
janders223 over 11 yearsThe name of your controller does not matter, so long as it inherits from
Devise::SessionsController
. -
umezo over 11 yearsah, just realized it's inheriting from
Devise::SessionsController
and not simplyDeviseController
. That makes sense, thanks. -
Yetanotherjosh about 11 yearsActually 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 justSesssionsController