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

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – 是否可以在活动管理中进行深度嵌套?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
这是我在Active Admin上碾压的第三天.

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

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

解决方法

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

我做了以下事情:

  1. form do |f|
  2. f.inputs "Details" do
  3. f.input :instructor,:as => :select
  4. f.input :title
  5. f.input :name
  6. f.input :price
  7. f.input :discount
  8. f.input :slug
  9. f.inputs "Sections" do
  10. f.has_many :sections,:header=>"" do |section|
  11. section.input :name
  12. section.input :position
  13. if section.object.id
  14. section.input :_destroy,:as=>:boolean,:required => false,:label=>'Remove'
  15. end
  16.  
  17. section.has_many :lessons,:header=>"Lessons" do |lesson|
  18. lesson.input :title
  19. lesson.input :position
  20. lesson.input :duration
  21. lesson.input :_destroy,:label=>'Remove'
  22. end
  23. end
  24. end
  25.  
  26. end
  27. f.buttons
  28. end

我的模型如下:

  1. class Course < ActiveRecord::Base
  2. has_many :sections,:dependent => :delete_all
  3. accepts_nested_attributes_for :sections,:allow_destroy => true
  4. attr_accessible :sections_attributes
  5. ....
  6.  
  7. class Section < ActiveRecord::Base
  8. belongs_to :course
  9. has_many :lessons,:dependent => :delete_all
  10. attr_accessible :course_id,:name,:position
  11. accepts_nested_attributes_for :lessons,:allow_destroy => true
  12. attr_accessible :lessons_attributes
  13. ....
  14.  
  15. class Lesson < ActiveRecord::Base
  16. belongs_to :section
  17. attr_accessible :duration,:position,:section_id,:title
  18. ....

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

猜你在找的Ruby相关文章