Rails 3 Tutorial 10.4.2 : NoMethodError undefined method `admin?' for nil:NilClass-Record and share programming errors

seems like you dont have a current user by the time you call ‘destroy’ method,

I think its because of this line

before_filter :admin_user,   :only => :destroy

and as you can see, you are setting current_user only in :index,:show,:edit, :update

before_filter :authenticate, :only => [:index,:show,:edit, :update]

Solution

adding :destroy to :authenticate method should fix the issue, and then by the time you try to destroy the current_user is there

before_filter :authenticate, :only => [:index,:show,:edit, :update, :destroy]

Originally posted 2013-08-31 06:13:25.