{"id":592,"date":"2022-08-30T15:03:55","date_gmt":"2022-08-30T15:03:55","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/issue-retrieving-current_user-in-devise-with-different-model-name-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:03:55","modified_gmt":"2022-08-30T15:03:55","slug":"issue-retrieving-current_user-in-devise-with-different-model-name-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/issue-retrieving-current_user-in-devise-with-different-model-name-collection-of-common-programming-errors\/","title":{"rendered":"Issue retrieving current_user in Devise with different model name-Collection of common programming errors"},"content":{"rendered":"<p>I have got Devise setup in my rails app with my model called auth_user instead of user. I have tried accessing the currently logged in user&#8217;s email address (a field called email) for me to use in a query against an Employee model like so<\/p>\n<pre><code>@employee = Employee.find_by_Email(current_auth_user.email)\n<\/code><\/pre>\n<p>but get the error:<\/p>\n<pre><code>undefined method `email' for nil:NilClass\n<\/code><\/pre>\n<p>Any ideas on how to resolve this issue?<\/p>\n<p>Thanks<\/p>\n<p>Paul<\/p>\n<p>** EDIT <strong><em>*<\/em>*<\/strong><\/p>\n<p>Fix as suggested by @theButler in the comments. Resolution was to add<\/p>\n<pre><code>before_filter :authenticate_auth_user!\n<\/code><\/pre>\n<p>To the top of the class.<\/p>\n<p id=\"rop\"><small>Originally posted 2013-11-09 21:06:45. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I have got Devise setup in my rails app with my model called auth_user instead of user. I have tried accessing the currently logged in user&#8217;s email address (a field called email) for me to use in a query against an Employee model like so @employee = Employee.find_by_Email(current_auth_user.email) but get the error: undefined method `email&#8217; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-592","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/592","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=592"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/592\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=592"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=592"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=592"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}