Hi There,
I have a pretty basic association:
# user.rb
class User < ActiveRecord::Base
has_many :services, :through => :subscriptions
has_many :subscriptions, :accessible => true
accepts_nested_attributes_for :subscriptions
end
# service.rb
class Service < ActiveRecord::Base
has_many :users, :through => :subscriptions
has_many :subscriptions
end
# subscription.rb
class Subscription < ActiveRecord::Base
belongs_to :user
belongs_to :service
end
The Subscription has also a boolean column "notification" which I need to configure individually, so i looked into the API, followed the example and came up with this code for my form:
- if current_user.subscriptions.length > 0
%fieldset#subscriptions
%legend Abonnements
%table
%tr
%th.name
%th.notification Notifications?
- for subscription in current_user.subscriptions do
%tr
- f.fields_for :subscriptions, subscription do |s|
%td=subscription.service.name
%td= s.check_box :notification
But when I save the Form, all associated subscriptions are destroyed. Whereas when I check the checkbox it wont be deleted, but the checkbox is not saved either. Does anyone know what I'm doing wrong?