Rails 3 + Devise: undefined variable or method 'record' in SessionsController
Hey, I defined the following method in my SessionsController to sign someone out:
def destroy
current_user.update_attribute(:signed_in => false) if record.respond_to?(signed_in?)
signed_in = signed_in?(resource_name)
sign_out_an开发者_StackOverflow中文版d_redirect(resource_name)
set_flash_message :notice, :signed_out if signed_in
end
but I always get this error:
undefined local variable or method `record' for #<Devise::SessionsController:0xbcd9780>
Seems to me that record.respond_to? tries to access ActiveRecord but can't. What should I do?
You can use the try method.
current_user.try("signed_in=", false); current_user.save
精彩评论