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) else ... end
Entry Filed under: Ruby on Rails