这是我在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 ....
而且效果很棒!我不知道如果我更深层次会发生什么.