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.

Reply

Can you post the actual error?

Reply
Reply

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?

Reply

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

Reply

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.

Reply

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.

Reply

Interesting, glad you got it! :D

Reply
Join the discussion
Create an account Log in

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

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

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