Public_activity - 在帐户取消后销毁用户的活动

Min*_*ohn 4 controller ruby-on-rails devise ruby-on-rails-4

我试图实现这一点,当用户删除他的帐户时,他的所有活动也会被删除.

我正在使用Rails 4 - Devise - 公共活动

我的注册控制器:

class RegistrationsController < Devise::RegistrationsController

  # DELETE /resource
  def destroy
    resource.destroy
    Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name)
    set_flash_message :notice, :destroyed if is_flashing_format?
    yield resource if block_given?
    respond_with_navigational(resource){ redirect_to after_sign_out_path_for(resource_name) }
  end

end
Run Code Online (Sandbox Code Playgroud)

在用户删除他使用的评论后销毁评论记录:

@activity = PublicActivity::Activity.find_by_trackable_id(params[:id])
@activity.destroy
Run Code Online (Sandbox Code Playgroud)

我正在寻找类似的东西,只是为了在帐户取消后销毁所有活动.

谁有好的解决方案?

rma*_*002 5

User.rb中添加一个回调:

 before_destroy :delete_activities

 def delete_activities
    acts = PublicActivity::Activity.where(owner_id: self.id, owner_type: "User")
    acts.delete_all
  end
Run Code Online (Sandbox Code Playgroud)