I 꽤 기본적인 관계를 fields_for :has_many 가진 문제점 : 통해
# 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
구독도 부울 열 I 개별적으로 구성 할 필요가 "통지"를 가지고, 그래서이 API 들여다 상기 따라 예를 들어 내 양식에이 코드를 사용했습니다.
- 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
그러나 양식을 저장하면 관련된 모든 구독이 삭제됩니다. 반면 확인란을 선택하면 삭제되지 않을 것이지만 체크 박스는으로 저장되지 않습니다. 아무도 내가 뭘 잘못하고 있는지 알아?
아무 것도 바뀌지 않습니다. 좋은 점은 있지만, 'for'는 전혀 필요하지 않습니다. –