我有3个型号。他们在那里:
class Client < ActiveRecord::Base
has_many :users, through: :client_users
has_many :client_users
accepts_nested_attributes_for :users, allow_destroy: true
accepts_nested_attributes_for :client_users, allow_destroy: true
end
class ClientUser < ActiveRecord::Base
belongs_to :client
belongs_to :user, autosave: false
accepts_nested_attributes_for :client
accepts_nested_attributes_for :user
end
class User < ActiveRecord::Base
has_many :clients, through: :client_users
has_many :client_users
accepts_nested_attributes_for :client_users
end
当我创建一个新客户端时,我已经为用户嵌套了表单。 目标是:如果新用户不存在则创建新用户,如果已存在则追加。 用户模型有唯一的电子邮件
哪种方法最好?