Rails - 将元素放入 Div 中,从使用 HAML 中的助手呈现的视图中

Rails - putting elements inside Div from view rendered using helper in HAML

我有两个创建功能模式的视图。第一个是用辅助方法制作的

.modal-header
  %button.close{"aria-hidden" => "true", "data-dismiss" => "modal", :type => "button"} ×
  %h3.modal-title
    = title
.modal-body
  (some necessary code)

然后是第二个文件,其中包含该模式的内容,如下所示:

generate_top(title)
(...)

现在,当 Rails 将其生成为 HTML 时,第二个视图的内容与 <div class="modal-body"> 分开。有什么好的方法可以将第二个文件的视图插入 modal-body div 而无需从第一个文件移动 class 声明?

好吧,毕竟我的问题找不到好的答案,所以我采取了不同的方法:

我没有使用助手生成 modal-header,而是像这样修改了模态布局:

#mainModal{:class => "modal", :tabindex => "-1", :role => "dialog" , "aria-labelledby" => "mainModalLabel", "aria-hidden" => "true"}
  .modal-dialog
    .modal-content
      .modal-header
        %button.close{"aria-hidden" => "true", "data-dismiss" => "modal", :type => "button"} &times;
        %h3.modal-title
          =yield :title if content_for? :title
      .modal-body
        (that necessary code that was mentioned before)
        =yield

现在我通过 content_for 方法将标题添加到模式:

=content_for :title do
  ={Modal title}