Search code examples
ruby-on-railscocoon-gem

link_to_add_association adding two partials instead of one


When I click on "Add User", two rows are added instead of one. 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 (partial/column being added):

= 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

Any ideas why?


Solution

  • Turns out it was due to an indentation error with tables in HTML.