Ruby on rails 3.2 递归部分(Ruby on Rails)中的即时加载

Ruby on rails 3.2 递归部分(Ruby on Rails)中的即时加载,ruby-on-rails-3.2,lazy-loading,Ruby On Rails 3.2,Lazy Loading,我有一个带有自联接的模型: class Audience < ActiveRecord::Base has_many :children, class_name: "Audience", foreign_key: "parent_id" belongs_to :parent, class_name: "Audience" end 提供程序有多个受众,其中有多个子受众(在受众表中) <%= render 'checkbox_for_children', :aud

我有一个带有自联接的模型:

  class Audience < ActiveRecord::Base
   has_many :children, class_name: "Audience", foreign_key: "parent_id"
   belongs_to :parent, class_name: "Audience"
  end 
提供程序有多个受众,其中有多个子受众(在受众表中)

<%= render 'checkbox_for_children', :audience => root_audience %>
<% children = audience.children %>

<ul class="list-unstyled">
  <% children.each do |child| %>
    <li>
      <% if child.targetable.present? %>
        <%= check_box_tag("demographic_data[#{child.name}]", child.demographic_id) %>
        <%= child.name %>
        <% if child.children.present? %>
           <%= render 'checkbox_for_children', :audience => child %>
        <% end %>
      <% else %>
        <%= child.name %>
        <% if child.children.present? %>
           <%= render 'checkbox_for_children', :audience => child %>
        <% end %>
      <% end %>
    </li>
  <% end %>
</ul>  
  def add_demographic
    @relevant_providers = Provider.have_audience
    render "add_demographic"
  end