No errors and no output for rails cocoon gem

喜夏-厌秋 提交于 2019-12-02 02:18:36

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!