是否可以在活动管理中进行深度嵌套?

pri*_*kha 8 ruby-on-rails nested-forms activeadmin

这是我在Active Admin上破坏的第三天.

我有@survey这个has_many :questions和每个问题has_many :answers- 它们实际上是用户可以选择的变种.

但是我仍然不能把它付诸实践,它只是没有创建更深层次的1级:即使表单正常工作,但没有创建任何东西.

Ton*_*ony 16

我有以下课程课程 - >章节 - >课程.

我做了以下事情:

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
Run Code Online (Sandbox Code Playgroud)

我的模型如下:

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
....
Run Code Online (Sandbox Code Playgroud)

而且效果很棒!我不知道如果我更深层次会发生什么.