小编roo*_*ada的帖子

Rails 3 Cocoon link_to_add_association渲染部分两次

正如预期的那样,我的部分渲染两次而不是一次.有什么想法吗?

这是我的人物观点

<%= simple_nested_form_for(@person) do |f| %>
  <%= f.error_notification %>

  <div class="form-inputs">

    <%= f.input :name %>

    <h3>Records by year</h3>

    <div id='records'>
      <%= f.simple_fields_for :records do |record| %>
        <%= render 'record_fields', :f => record %>
      <% end %>

      <div class='links'>
        <%= link_to_add_association 'New Record', f, :records, :class => 'btn' %>
      </div>
    </div>

  </div>

  <div class="form-actions">
    <%= f.button :submit %>
  </div>
<% end %>
Run Code Online (Sandbox Code Playgroud)

模型(删除常量和验证等内容):

class Person < ActiveRecord::Base

    attr_accessible :name, :records_attributes

    has_many :records, :dependent => :destroy
    accepts_nested_attributes_for :records, :reject_if => :all_blank, …
Run Code Online (Sandbox Code Playgroud)

nested-attributes ruby-on-rails-3 cocoon-gem

7
推荐指数
1
解决办法
3640
查看次数