HAML Bootstrap 4 and rails - 根据局部变量展开手风琴
HAML Bootstrap 4 and rails - Expand accordion based on local variable
我有一个包含课程的 rails 应用程序。每门课程都有章节,每一章都有课程。我正在使用 bootstrap 手风琴来显示当前课程的章节和课程列表,但无法弄清楚如何让用户展开当前章节,但将其余章节折叠起来。我试过在底线下添加渲染课程,尝试了一些javascript,不同级别的缩进。手风琴奏效了,但一切都开始展开了。
#accordion
.list-group#scrollable
- @chapters.each do |chapter|
.panel.panel-default
.list-group-item.shadow
%a{"data-parent" => "#accordion", "data-toggle" => "collapse", :href => "#collapse#{chapter.id}"}
= render 'chapters/chapter_preview', chapter: chapter
-if @lesson.chapter_id = chapter.id
.panel-collapse.collapse.show{:id => "collapse#{chapter.id}"}
- chapter.lessons.rank(:row_order).each do |lesson|
.panel-body
- if lesson.eql?(@lesson)
%li.list-group-item.list-group-item-success
= render 'lessons/lesson_student', lesson: lesson
- else
%li.list-group-item.list-group-item-secondary
= render 'lessons/lesson_student', lesson: lesson
-else
.panel-collapse.collapse.in{:id => "collapse#{chapter.id}"}
您输入错误可能会导致问题
- if @lesson.chapter_id = chapter.id
# should be
- if @lesson.chapter_id == chapter.id
# if lesson belongs_to chapter and chapter has_many lessons you could even get rid of the id:
- if @lesson.chapter == chapter
我有一个包含课程的 rails 应用程序。每门课程都有章节,每一章都有课程。我正在使用 bootstrap 手风琴来显示当前课程的章节和课程列表,但无法弄清楚如何让用户展开当前章节,但将其余章节折叠起来。我试过在底线下添加渲染课程,尝试了一些javascript,不同级别的缩进。手风琴奏效了,但一切都开始展开了。
#accordion
.list-group#scrollable
- @chapters.each do |chapter|
.panel.panel-default
.list-group-item.shadow
%a{"data-parent" => "#accordion", "data-toggle" => "collapse", :href => "#collapse#{chapter.id}"}
= render 'chapters/chapter_preview', chapter: chapter
-if @lesson.chapter_id = chapter.id
.panel-collapse.collapse.show{:id => "collapse#{chapter.id}"}
- chapter.lessons.rank(:row_order).each do |lesson|
.panel-body
- if lesson.eql?(@lesson)
%li.list-group-item.list-group-item-success
= render 'lessons/lesson_student', lesson: lesson
- else
%li.list-group-item.list-group-item-secondary
= render 'lessons/lesson_student', lesson: lesson
-else
.panel-collapse.collapse.in{:id => "collapse#{chapter.id}"}
您输入错误可能会导致问题
- if @lesson.chapter_id = chapter.id
# should be
- if @lesson.chapter_id == chapter.id
# if lesson belongs_to chapter and chapter has_many lessons you could even get rid of the id:
- if @lesson.chapter == chapter