Nested attributes for one-to-one relation
问题 I have a Company which has one Subscription. Now I want a form to add or edit the company and the subscription, so I use "accepts_nested_attributes_for". This is (part of) the Company model: has_one :subscription, :dependent => :destroy accepts_nested_attributes_for :subscription This is (part of) the Subscription model: belongs_to :company In the controller I have this: def new @company = Company.new(:subscription => [Subscription.new]) end def create @company = Company.new(params[:company])