[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.