嵌套的fields_for未显示

时间:2018-11-25 08:44:14

标签: ruby-on-rails ruby-on-rails-4 form-for

具有以下结构:

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"

但是正确显示了与注册相关的fields_for。我尝试将'registration.fields_for'用作'childs'字段的'fields_for',但它也没有帮助。 没有错误,只是不显示。任何现有的问题都没有帮助

0 个答案:

没有答案