2016-10-24 30 views
0

我在ActiveAdmin中遍歷3個has_many關係來顯示信息。我想以父,子格式顯示信息。目前我有一個活動,活動內有很多地點,每個地點有很多日期,每個日期有很多大使(用戶)。遍歷多個has_many關係並顯示每個人所屬的內容。 Active Admin

我希望顯示信息,以便查看活動的位置,然後查看由地點分隔的日期以及由日期分隔的大使(用戶)。 這是我目前編寫的代碼,但它沒有給我父親的孩子顯示器,我正在尋找。

show do 

attributes_table do 
row :agency 
row :name 
row :event_details 
row :created_at 

panel "Locations" do 
    attributes_table_for event.event_locations do 
    row :label 
    row :address 
    row :zip 
    row :state 
    row :country 
    row :notes 
    panel "Event dates" do 
     event.event_locations.each do |r| 
     attributes_table_for r.event_dates do 
     row :event_date 
     panel "Ambassadors" do 
      attributes_table_for event.booking.booking_staff do 

       row :ambassador 

     end 
     end 

    end 
    end 
end 
    end 
end 
    end 
active_admin_comments end 

正如你可以看到上面的代碼,我不會得到預期的結果。任何建議將不勝感激。謝謝。

回答

0

也許這會讓你指向正確的方向。請確保您更改了

:attribute_of_event_date 

和類似的符號,因此它們在數據(模型)的上下文中有意義。祝你好運!

panel "Locations" do 
    resource.event_locations.each do |event_location| 

    attributes_table_for event_location do 
     row :label 
     row :address 
     row :zip 
     row :state 
     row :country 
     row :notes 

     panel "Event dates" do 
     event_location.event_dates.each do |event_date| 

      attributes_table_for event_date do 
      row :attribute_of_event_date 
      row :another_attribute_of_event_date 
      panel "Ambassadors" do 
       event_date.ambassadors.each do |ambassador| 

       attributes_table_for ambassador do 
        row :atttribute_of_ambassador 
        row :another_atttribute_of_ambassador 
       end 
       end 

      end 
      end 

     end 
     end 
    end 
    end 
end