Devise Edge Case

September 29th, 2011

Long time no blog. Since RailsConf, I’ve been A) Working my tail off at my new job B) finding a new place to live C) reminding my children that they do have a mommy

A) Has been fun and incredibly challenging. But while working at home is amazing, it means I work a lot B) took a lot more time and effort than I ever could have imagined so that there hasn’t been much time for C). So all other endeavors have been on hold.

But now it’s fall and with the change of seasons comes a renewed passion for picking up old projects. I have better sense now than to attempt to watch and blog every single Railscasts episode (unless someone locks me in a closet for a week….which would be awesome). So instead I’m just gonna share a tidbit from work. Hopefully it’ll help someone out.

I recently ripped out Authlogic and implemented Devise at work. I used the Rails 3.0 app using Devise + Omniauth example on github as a guide. And thanks to StackOverflow, I came out relatively unscathed. But I did find one edge case that might interest someone.

We were getting this error:

NoMethodError (undefined method `serialize_into_session' for Symbol:Class):

And after a little debugging came to realize that we had user_tokens with no matching user. (There’s database integrity for ya). Fortunately, it’s a quick fix in app/controllers/members/omniauth_callbacks_controller.rb. You just need to add authentication.user.present?.

authentication = UserToken.find_by_provider_and_uid(omniauth['provider'], omniauth['uid'])
if authentication && authentication.user.present?
  flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => omniauth['provider']
  sign_in_and_redirect(:user, authentication.user)
  #sign_in_and_redirect authentication.user, :event => :authentication)

Entry Filed under: Ruby on Rails

2 Comments Add your own

  • 1. iļja  |  March 14th, 2012 at 8:46 pm

    Thank you, I was hit by this too.

  • 2. Shantanu Kangude  |  September 7th, 2012 at 4:26 am

    Thank you! Saved me some debugging time :-)

Leave a Comment


Required, hidden

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed




Recent Posts