{"id":244,"date":"2022-08-30T14:58:07","date_gmt":"2022-08-30T14:58:07","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/08\/31\/rails-3-tutorial-10-4-2-nomethoderror-undefined-method-admin-for-nilnilclass-record-and-share-programming-errors\/"},"modified":"2022-08-30T14:58:07","modified_gmt":"2022-08-30T14:58:07","slug":"rails-3-tutorial-10-4-2-nomethoderror-undefined-method-admin-for-nilnilclass-record-and-share-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/rails-3-tutorial-10-4-2-nomethoderror-undefined-method-admin-for-nilnilclass-record-and-share-programming-errors\/","title":{"rendered":"Rails 3 Tutorial 10.4.2 : NoMethodError undefined method `admin?&#39; for nil:NilClass-Record and share programming errors"},"content":{"rendered":"<p>seems like you dont have a current user by the time you call &#8216;destroy&#8217; method,<\/p>\n<p>I think its because of this line<\/p>\n<pre><code>before_filter :admin_user,   :only =&gt; :destroy\n<\/code><\/pre>\n<p>and as you can see, you are setting current_user only in :index,:show,:edit, :update<\/p>\n<pre><code>before_filter :authenticate, :only =&gt; [:index,:show,:edit, :update]\n<\/code><\/pre>\n<p><strong>Solution<\/strong><\/p>\n<p>adding :destroy to :authenticate method should fix the issue, and then by the time you try to destroy the current_user is there<\/p>\n<pre><code>before_filter :authenticate, :only =&gt; [:index,:show,:edit, :update, :destroy]\n<\/code><\/pre>\n<p id=\"rop\"><small>Originally posted 2013-08-31 06:13:25. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>seems like you dont have a current user by the time you call &#8216;destroy&#8217; method, I think its because of this line before_filter :admin_user, :only =&gt; :destroy and as you can see, you are setting current_user only in :index,:show,:edit, :update before_filter :authenticate, :only =&gt; [:index,:show,:edit, :update] Solution adding :destroy to :authenticate method should fix the [&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-244","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/244","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=244"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/244\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=244"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=244"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=244"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}