No errors and no output for rails cocoon gem

前端 未结 1 955
离开以前
离开以前 2021-01-21 08:08

I am working on a dynamically nested form using the cocoon gem. I have two models

class CrossTable < ActiveRecord::Base
  attr_accessible :title, :table_name         


        
相关标签:
1条回答
  • 2021-01-21 09:09

    You wrote the link_to_add_association inside the simple_fields_for, which will loop over all :foreign_fields and execute the given block. So if there are no foreign-fields yet, the link_to_add_association is never shown.

    You should write your view as follows (as documented):

    <%= simple_form_for @table do |f| %>
        <%= f.input :title %>
    
        <%= f.input :folder_label_id, :collection => @folders, :label_method => :title, :value_method => :id %>
        <br><br>
        <%= f.input :table_name %>
        <%= f.input :database %>
    
        <%= f.simple_fields_for :foreign_fields do |fields| %>
            <%= render 'foreign_field_fields', :f => fields %>
        <% end %>
        <div id='links'>
          <%= link_to_add_association 'Add Field', f, :foreign_fields %>
        </div>
    
        <%= f.button :submit %>
    
    <% end %>
    

    Hope this helps.

    0 讨论(0)
提交回复
热议问题