ruby-on-rails – 是否可以在活动管理中进行深度嵌套?

这是我在Active Admin上碾压的第三天.

我有@survey has_many:问题和每个问题has_many:答案 – 它们实际上是用户可以选择的变体.

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

解决方法

我有以下条款课程 – >章节 – >课程.

我做了以下事情:

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,: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
....

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

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...