Jak wywołać after_destroy callback w tym przypadku?

[code=ruby]# == Schema Information

Table name: subscriptions

app_id :integer

id :integer not null, primary key

user_id :integer

Table name: apps

id :integer not null, primary key

name :string(255)

user_id :integer

App
has_many :subscriptions
has_many :users, through: :subscriptions
User
belongs_to :app
has_many :subscriptions, :dependent => :destroy
Subscription
belongs_to :user
belongs_to :app

def set_subscriptions
if params[:subscription] and params[:subscription][:app_ids] #call it app_ids since you’re getting an array of them.
apps = App.find(params[:subscription][:app_ids])
current_user.apps = apps
else
current_user.apps = []
end
end
current_user.save[/code]
Jak w tym przypadku wywołać coś takiego:

# subscription.rb after_destroy :destroy_app_from_feed def destroy_app_from_feed logger.info("subscription destroyed") end
Chciałbym po prostu dla odznaczonych subsckrypcji wywołać after_destroy callback i usunąć feedy z Redisa.

[code=ruby]# zamiast
if params[:subscription] and params[:subscription][:app_ids] #call it app_ids since you’re getting an array of them.
apps = App.find(params[:subscription][:app_ids])
current_user.apps = apps
else
current_user.apps = []
end
end

możesz

current_user.apps = App.find(params.try(:[], ‘subscription’).try(:[], ‘app_ids’) || [][/code]
Jeśli w after_destroy masz id usuwanego obiektu subscription to po prostu odpal metodę redisa z parametrem self. O to chodziło?

Hmm, zrobiłem tak:

[code=ruby] has_many :apps, through: :subscriptions, after_remove: :after_group_destroy

def after_group_destroy(group)
UserFeed.remove_group_items(self, group)
end[/code]