2011-11-22 31 views
7

這是我在Active Admin上粉碎的第三天。是否有可能在活動管理員中進行深層嵌套?

我有@surveyhas_many :questions和每個問題has_many :answers - 它們實際上是用戶可以選擇的變體。

但是我還是不能把它運用起來,它只是不會創造出更深層次的東西: 即使表格正常工作,也沒有創建任何東西。

+0

將代碼粘貼到您的模型和活動的管理資源實施 – JCorcuera

+1

查看此ActiveAdmin問題中的評論。和其他問題包含「嵌套」。 https://github.com/gregbell/active_admin/issues/478並觀看這裏太:http://stackoverflow.com/questions/8224884/nested-form-in-active-admin – slothbear

+0

多數民衆贊成在我的問題*))) – prikha

回答

14

我有以下課程課程 - >部分 - >課程。

我做了以下內容:

form do |f| 
    f.inputs "Details" do 
    f.input :instructor, :as => :select 
    f.input :title 
    f.input :name 
    f.input :price 
    f.input :discount 
    f.input :slug 
    f.inputs "Sections" do 
     f.has_many :sections, :header=>"" do |section| 
     section.input :name 
     section.input :position 
     if section.object.id 
      section.input :_destroy, :as=>:boolean, :required => false, :label=>'Remove' 
     end 

     section.has_many :lessons, :header=>"Lessons" do |lesson| 
      lesson.input :title 
      lesson.input :position 
      lesson.input :duration 
      lesson.input :_destroy, :as=>:boolean, :required => false, :label=>'Remove' 
     end 
     end 
    end 

    end 
    f.buttons 
end 

我的模型如下:

class Course < ActiveRecord::Base 
    has_many :sections, :dependent => :delete_all 
    accepts_nested_attributes_for :sections, :allow_destroy => true 
    attr_accessible :sections_attributes 
.... 

class Section < ActiveRecord::Base 
    belongs_to :course 
    has_many :lessons, :dependent => :delete_all 
    attr_accessible :course_id, :name, :position 
    accepts_nested_attributes_for :lessons, :allow_destroy => true 
    attr_accessible :lessons_attributes 
.... 

class Lesson < ActiveRecord::Base 
    belongs_to :section 
    attr_accessible :duration, :position, :section_id, :title 
.... 

而且它的偉大工程!我不知道如果我深入更深層次會發生什麼。

+2

不錯!我已經解決了。但希望這可以幫助別人! – prikha

+1

@tony如果我們正在使用HABTM協會,然後???我們需要做什麼? –

+1

rails 4的任何更新?看來受保護的屬性現在在控制器中設置。我們需要使用'permit_params'? – Defoncesko

相關問題