使用haml在bootstrap模式中创建simple_form

时间:2018-02-21 03:26:51

标签: ruby-on-rails twitter-bootstrap-3 haml simple-form

我正在尝试在视图中使用simple_form的Ruby 2.5 on Rails(v5.1)中的Bootstrap 3模式中使用haml

我希望能够将提交按钮放在模态页脚中,但这会破坏haml约定。任何解决方法?

模态

#addDataModelModal.modal.fade{"aria-hidden" => "true", "aria-labelledby" => "exampleModalLabel", role: "dialog", tabindex: "-1"}
  .modal-dialog{role: "document"}
    .modal-content
      .modal-header
        %h5#addDataModelModalLabel.modal-title Choose a Data Model
        %button.close{"aria-label" => "Close", "data-dismiss" => "modal", type: "button"}
          %span{"aria-hidden" => "true"} ×
      .modal-body
        .text-center
          = simple_form_for @project, :url => add_project_datastores_project_path, :method => 'post' do |f|
            = f.input :project_datastores, collection: @datastores, label_method: :name, value_method: :datastore_sid, prompt: "Select a Data Model"
            = f.submit 'Add Data Model', :class => 'pull-right btn btn-primary'
      .modal-footer
        %button.btn.btn-secondary{"data-dismiss" => "modal", type: "button"} Close
        .text-center

1 个答案:

答案 0 :(得分:2)

= simple_form_for div下面的.modal-content开始,这样您就可以将f变量插入其所有子级div中。

#addDataModelModal.modal.fade{"aria-hidden" => "true", "aria-labelledby" => "exampleModalLabel", role: "dialog", tabindex: "-1"}
  .modal-dialog{role: "document"}
    .modal-content
      = simple_form_for @project, :url => add_project_datastores_project_path, :method => 'post' do |f|
        .modal-header
          %h5#addDataModelModalLabel.modal-title Choose a Data Model
          %button.close{"aria-label" => "Close", "data-dismiss" => "modal", type: "button"}
            %span{"aria-hidden" => "true"} ×
        .modal-body
          .text-center
            = f.input :project_datastores, collection: @datastores, label_method: :name, value_method: :datastore_sid, prompt: "Select a Data Model"
        .modal-footer
          %button.btn.btn-secondary{"data-dismiss" => "modal", type: "button"} Close
          .text-center
            = f.submit 'Add Data Model', :class => 'pull-right btn btn-primary'