0
po I am with a question already a while breaking the head, next, I have a model Person, which is the Generica for person and the model Customer, which belongs to Person, so:
class Person < ActiveRecord::Base
has_one :customer
has_one :address, as: :addressable
has_one :phone, as: :phoneable
accepts_nested_attributes_for :address, allow_destroy: true, reject_if: :all_blank
accepts_nested_attributes_for :phone, allow_destroy: true, reject_if: :all_blank
accepts_nested_attributes_for :customer, allow_destroy: true, reject_if: :all_blank
end
and Customer:
class Customer < ActiveRecord::Base
belongs_to :person
has_one :address, as: :addressable
has_one :phone, as: :phoneable
validates :person_id, presence: true
accepts_nested_attributes_for :phone, allow_destroy: true, reject_if: :all_blank
accepts_nested_attributes_for :address, allow_destroy: true, reject_if: :all_blank
accepts_nested_attributes_for :person, allow_destroy: true, reject_if: :all_blank
end
In Customer_controller I set the Strong params to accept the attributes of Person when created, thus:
def customer_params
params.require(:customer).permit(
:customer_code, :name, :cpf, :rg, :birthdate,
addresses_attributes: [:id, :street, :number, :neighborhood, :state, :nation],
person_attributes: [:id, :name, :cpf, :rg, :birthdate],
phones_attributes: [:id, :phone1, :phone2])
end
In the form I entered the simple_fields_for :person of |ff| But you are not registering the person, only the person.
If you can help.
Hello Breno, thank you for the answer, just to answer your questions, a person has a consumer because a consumer is a person, and the Rails version is 4.2.6
– Jean Felipe