Devise destroy registration action to also destroy all authentications?
I'm using DEvise for registration and omniauth for authentication through twitter/facebook, I want to destroy all authentications when a users destroys his account registration with Devise. What do I need to add to my registrations destroy method for this?
RegistrationsController < Devise::RegistrationsController
def destroy
resource.destroy
set_flash_mes开发者_如何学Csage :notice, :destroyed
sign_out_and_redirect(self.resource)
end
AuthenticationsController
def destroy
@authentication = current_user.authentications.find(params[:id])
@authentication.destroy
flash[:notice] = "Successfully destroyed authentication."
redirect_to authentications_url
end
I think you followed rbates on this one. The way he set it up was users having many authentications so correct me if I'm wrong.
You just need this:
class User < ActiveRecord::Base
has_many :authentications, :dependent => :destroy
end
精彩评论