Вложенные fields_for не отображается - PullRequest
0 голосов
/ 25 ноября 2018

Существует следующая структура:

class Child < ActiveRecord::Base
  attr_accessible :name, :gender, :birthday, :allergies
  has_one :registration
  has_one :user, through: :registration, source: :student, class_name: User
end

class Registration < ActiveRecord::Base
  belongs_to :student, class_name: 'User'
  belongs_to :child

  accepts_nested_attributes_for :child
end

class User < ActiveRecord::Base
  has_many :registrations, foreign_key: :student_id
  has_many :children, through: :registrations
end

И проблема в том, что здесь не отображаются дочерние поля:

  = form_for model, url: order_path(model.id),
  html: { method: :put, validate: true, class: 'process-checkout' } do |order|
    = render 'close_button'

    - capture do # workaround, cell has broken block handling
      = hidden_field_tag :rc_id, params[:rc_id]
      = hidden_field_tag :next, 'promo'

      .modal-body
        .contact-form
          %h3 YOUR CONTACT INFO
          .error= errors
          - order_registrations.each_with_index do |reg, i|
            = order.fields_for :"registrations[#{i}]", reg do |registration|
              .row
                .form-group.col-xs-12.col-sm-6
                  = registration.text_field :student_first_name, label: false, required: i.zero?,
                  placeholder: "First name", class: "form-control", value: first_name(registration.object, i)
              - if model.course.kids_class?
                - fields_for :child, (reg.child || reg.build_child) do |child|
                  .row
                    .form-group.col-xs-12.col-sm-6
                      = child.text_field :allergies, label: false, placeholder: "Child Allergies", class: "form-control"

Но поля, связанные с регистрацией, отображаются правильно.Я попытался использовать в качестве «registration.fields_for» как «fields_for» для «дочерних» полей, но это тоже не помогло.Ошибок нет, просто не отображается.Ни один существующий вопрос не помог

...