{"id":1237,"date":"2011-09-29T20:59:50","date_gmt":"2011-09-30T00:59:50","guid":{"rendered":"http:\/\/blogs.law.harvard.edu\/lianaleahy\/?p=1237"},"modified":"2012-04-27T12:19:09","modified_gmt":"2012-04-27T16:19:09","slug":"devise-edge-case","status":"publish","type":"post","link":"https:\/\/archive.blogs.harvard.edu\/lianaleahy\/2011\/09\/29\/devise-edge-case\/","title":{"rendered":"Devise Edge Case"},"content":{"rendered":"<p>Long time no blog. Since RailsConf, I&#8217;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<\/p>\n<p>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&#8217;t been much time for C). So all other endeavors have been on hold.<\/p>\n<p>But now it&#8217;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 <a title=\"Railscasts\" href=\"http:\/\/http:\/\/railscasts.com\/\">Railscasts<\/a> episode (unless someone locks me in a closet for a week&#8230;.which would be awesome). So instead I&#8217;m just gonna share a tidbit from work. Hopefully it&#8217;ll help someone out.<\/p>\n<p>I recently ripped out Authlogic and implemented Devise at work. I used the <a href=\"http:\/\/https:\/\/github.com\/plataformatec\/devise\/wiki\/Example-Applications\">Rails 3.0 app using Devise + Omniauth<\/a> example on github as a guide. And thanks to <a href=\"http:\/\/stackoverflow.com\">StackOverflow<\/a>, I came out relatively unscathed. But I did find one edge case that might interest someone.<\/p>\n<p>We were getting this error:<br \/>\n<code><br \/>\nNoMethodError (undefined method `serialize_into_session' for Symbol:Class):<br \/>\n<\/code><\/p>\n<p>And after a little debugging came to realize that we had user_tokens with no matching user.  (There&#8217;s database integrity for ya).  Fortunately, it&#8217;s a quick fix in <strong>app\/controllers\/members\/omniauth_callbacks_controller.rb<\/strong>.  You just need to add authentication.user.present?.<\/p>\n<pre>\r\nauthentication = UserToken.find_by_provider_and_uid(omniauth['provider'], omniauth['uid'])\r\nif authentication &amp;&amp; <strong>authentication.user.present?<\/strong>\r\n  flash[:notice] = I18n.t \"devise.omniauth_callbacks.success\", :kind =&gt; omniauth['provider']\r\n  sign_in_and_redirect(:user, authentication.user)\r\n  #sign_in_and_redirect(authentication.user, :event =&gt; :authentication)\r\nelse\r\n  ...\r\nend\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Long time no blog. Since RailsConf, I&#8217;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) [&hellip;]<\/p>\n","protected":false},"author":1911,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[2403],"tags":[],"class_list":["post-1237","post","type-post","status-publish","format-standard","hentry","category-ruby-on-rails"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/archive.blogs.harvard.edu\/lianaleahy\/wp-json\/wp\/v2\/posts\/1237","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/archive.blogs.harvard.edu\/lianaleahy\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/archive.blogs.harvard.edu\/lianaleahy\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/archive.blogs.harvard.edu\/lianaleahy\/wp-json\/wp\/v2\/users\/1911"}],"replies":[{"embeddable":true,"href":"https:\/\/archive.blogs.harvard.edu\/lianaleahy\/wp-json\/wp\/v2\/comments?post=1237"}],"version-history":[{"count":7,"href":"https:\/\/archive.blogs.harvard.edu\/lianaleahy\/wp-json\/wp\/v2\/posts\/1237\/revisions"}],"predecessor-version":[{"id":1288,"href":"https:\/\/archive.blogs.harvard.edu\/lianaleahy\/wp-json\/wp\/v2\/posts\/1237\/revisions\/1288"}],"wp:attachment":[{"href":"https:\/\/archive.blogs.harvard.edu\/lianaleahy\/wp-json\/wp\/v2\/media?parent=1237"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/archive.blogs.harvard.edu\/lianaleahy\/wp-json\/wp\/v2\/categories?post=1237"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/archive.blogs.harvard.edu\/lianaleahy\/wp-json\/wp\/v2\/tags?post=1237"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}