假设用户 has_one :subscription,Subscription belongs_to :user,我使用accepts_nested_attributes_for 将订阅属性嵌套到用户创建表单中,基于User.email 定位和更新现有订阅(如果存在)的最佳方法是什么==订阅电子邮件?
请注意,现有订阅可能有 user_id = nil
假设用户 has_one :subscription,Subscription belongs_to :user,我使用accepts_nested_attributes_for 将订阅属性嵌套到用户创建表单中,基于User.email 定位和更新现有订阅(如果存在)的最佳方法是什么==订阅电子邮件?
请注意,现有订阅可能有 user_id = nil
可能您想要做的是使用电子邮件作为外键:
class User < ActiveRecord::Base
has_one :subscription, :foreign_key => "email", :primary_key => "email"
end
我想这需要分为两个步骤: