Search code examples
ruby-on-railsdeviseinitializer

Changed devise initializer, now authentication is broken


I had tried to setup username based authentication in devise's initializer to begin with; but that turned out to require more work than I was willing to put into this app at this moment as it's just for mucking around with. So where I had initially had config.authentication_keys = [ :username ], amongst other config settings, I changed them all back to :email.

Problem is though, now when I try and log in I now get the following error:

NoMethodError in Devise::SessionsController#create
undefined method `email' for #<ActionDispatch::Request:0xrequestid>

I suspect it's related to my initial foray into username based authentication, but I can't tell where the actual problem/residual configuration is that I now need to address as I'm very new to Rails.

I'm more than happy to provide whatever logs/configuration/you name it. I just don't know what would be helpful at this point.


Solution

  • Ok it turns out that I shouldn't have specified the config.authentication_keys and config.request_keys when I changed them back to [:email] (the default). For whatever reason (which I don't know yet) this required me to specify the strong parameters, which were identical to what devise would have specified if I just left those lines commented.

    So the simple solution is to not specify things if you are using the default value.