Rails连接表没有填充

时间:2012-01-06 21:08:25

标签: ruby-on-rails activerecord has-and-belongs-to-many

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不会填充

0 个答案:

没有答案