class ReminderTemplate < ActiveRecord::Base
has_and_belongs_to_many :contacts
has_and_belongs_to_many :groups
end
class Group < ActiveRecord::Base
has_and_belongs_to_many :reminder_templates
has_and_belongs_to_many :contacts
end
class Contact < ActiveRecord::Base
has_and_belongs_to_many :reminder_templates
has_and_belongs_to_many :groups
end
def create
@reminder_template = ReminderTemplate.new(params[:reminder_template])
@reminder_template.group_ids = params[:template_selected_groups]
@reminder_template.contact_ids = params[:template_selected_contacts]
@reminder.save
end
当我使用联系人,组或两者创建提醒模板时,联接表contacts_reminder_templates和groups_reminder_templates不会填充