I'm sur I do it wrong, but I can't see where. I've got this two models :
Subscription.rb (child)
class Subscription < ActiveRecord::Base
attr_accessible :state, :subscriber_id, :subscriber_type, :last_payment
belongs_to :subscriber, polymorphic: true
validates :subscriber_id, presence: true
validates :subscriber_type, presence: true
end
restorer.rb (Parent)
class Restorer < User
attr_accessible :firstname, :lastname, :restaurant_attributes, :subscription_attributes
has_one :restaurant, dependent: :destroy, :autosave => true
has_one :subscription, as: :subscriber, :autosave => true
accepts_nested_attributes_for :restaurant
accepts_nested_attributes_for :subscription
end
When I want two create a new restorer, and a new subscription (at the same time) It doesn't work :
def create
@restorer = Restorer.create params[:restorer]
@restaurant = @restorer.build_restaurant params[:restorer][:restaurant_attributes]
@subscription = @restorer.build_subscription params[:restorer][:subscription_attributes]
if @restorer.save
...
else
...
end
end