link_to_add_association添加两个部分而不是一个

时间:2018-09-28 12:05:08

标签: ruby-on-rails cocoon-gem

当我单击“添加用户”时,将添加两行而不是一行。 See it here

new.html.slim:

= page_header

= simple_form_for @instance, url: admin_instance_users_path, method: :post do |f|
  = f.error_notification
  table.table.table-hover
    thead
    tr
      th = t('common.name')
      th = t('common.email')
      th = t('common.role')
      th
        div.pull-right
          = link_to_add_association t('.individual.add_user'), f, :invitations,
                  find_selector: 'tbody', insert_using: 'append'
      tbody
        = f.simple_fields_for :invitations, @instance.invitations.select(&:new_record?) do |invitation_form|
          = render 'invitation_fields', f: invitation_form

  = f.button :submit

_invitation_fields.html.slim(正在添加部分/列):

= content_tag_for(:tr, f.object, class: 'nested-fields') do
  td = f.input :name, label: false, input_html: { class: 'invitation_name' }
  td = f.input :email, required: true, label: false, input_html: { class: 'invitation_email' }
  td = f.input :role,
               as: :select,
               collection: Instance::UserInvitation.roles.keys,
               label: false,
               label_method: lambda { |role_key| t("instance.users.role.#{role_key}") },
               include_blank: false,
               input_html: { class: 'invitation_role' }
  td = link_to_remove_association  t('.remove'), f

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

原来是由于HTML中的表格缩进错误所致。