All threads / Devise - logging on with something other than email

Ask A Question

Notifications

You’re not receiving notifications from this thread.

Devise - logging on with something other than email

RJ McCollam asked in Gems / Libraries

I have followed the instructions on this page https://github.com/plataformatec/devise/wiki/How-To:-Allow-users-to-sign-in-with-something-other-than-their-email-address to allow signing in with something other than the email, but when I try to login I get an error of unidentified method for the new key I am using. In this case student_id. I am able to create an account with the student id and email just fine.

In application_controller.rb I have added the parameters for both sign up and sign in.

  before_action :configure_permitted_parameters, if: :devise_controller?

  private

    def configure_permitted_parameters
        devise_parameter_sanitizer.permit(:sign_up, keys: [:student_id, :email, :password, :password_confirmation])
        devise_parameter_sanitizer.permit(:sign_in, keys: [:student_id, :password])
    end

In the devise initializer I have added the link config.authentication_keys = [:student_id]

Not sure what else I am missing, and don't know enough to read into the error all that well.

Can you post the actual error?

Interesting, so the error was on the ActionDispatch Request object. Can you click the full trace tab and screenshot that too? Assuming your form passes in the student_id, I'd assume that'd be available.

Obvious thing: Did you restart Rails after changing the initializer?

Yes I did restart rails a few times to make sure it wasn't something silly like that.

The full trace can be found here - http://www.awesomescreenshot.com/image/2486026/389892e4c6723ca10f0a40718c89bdba

I figured. Hmm. This guy overrode the method to include a scope to fix his. https://github.com/plataformatec/devise/issues/3357

I know I've added a login key to this before without having to do this though.

I had the config.resource_keys uncommented for some reason and once I commented it out all worked as expected.

Thanks for your help here Chris.

Interesting, glad you got it! :D

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 37,344+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.