2017-06-06 69 views
0

能给予我仍然不清楚为什么这个打破:Haml打破。非法嵌套:内容无法同时在同一行

.form-box 
     %h3 Restrictions 
     %legend Restricted Locations 
     = form_for [:blueadmin, :wine, @wine], html: {class: 'form-horizontal col-lg-2'} do |f| 
      %fieldset.inputs 
      .control-group 
       = f.label :us_states, "US States", class: 'control-label' 
       .controls 
       = f.collection_select :product, Restriction.all, :us_state, :us_state, {}, :multiple => 'true' 
      %fieldset 
      %ol 
       %li.button 
       = f.submit "Submit", class: 'btn btn-primary' 
     %table.table.table-hover.table-condensed.story-list 
     %th State 
     %th Remove 

我得到的错误是: Illegal nesting: content can't be both given on the same line as %legend and nested within it.

= form_for似乎是元凶

我知道受限位置与%legend相同......但这就是我看文档的方式。

这工作,虽然,但它搞砸了我的传说边境:

.form-box 
     %h3 Restrictions 
     %legend 
     Restricted Locations 
     = form_for [:blueadmin, :wine, @wine], html: {class: 'form-horizontal col-lg-2'} do |f| 
      %fieldset.inputs 
      .control-group 
       = f.label :us_states, "US States", class: 'control-label' 
       .controls 
       = f.collection_select :product, Restriction.all, :us_state, :us_state, {}, :multiple => 'true' 
      %fieldset 
      %ol 
       %li.button 
       = f.submit "Submit", class: 'btn btn-primary' 
    %table.table.table-hover.table-condensed.story-list 
     %th State 
     %th Remove 

它看起来像这样:

enter image description here

,而不是这样的: enter image description here

(注意如何细线在不同的地方)

最后,我如何让底部的表格出现在表单的右侧,而不是底部?我如何使用列来做到这一点?

+0

压痕结果的任何变化,我不知道你应该做的'= form_for'。每当我在haml中使用'form_for',它就是' - form_for'。 – stef

回答

1

您有嵌套在图例元素中的表单。

.form-box 
    %h3 Restrictions 
    %legend 
    Restricted Locations 
    = form_for [:blueadmin, :wine, @wine], html: {class: 'form-horizontal col-lg-2'} do |f| 
    %fieldset.inputs 
     .control-group 
     = f.label :us_states, "US States", class: 'control-label' 
     .controls 
      = f.collection_select :product, Restriction.all, :us_state, :us_state, {}, :multiple => 'true' 
    %fieldset 
     %ol 
     %li.button 
      = f.submit "Submit", class: 'btn btn-primary' 
%table.table.table-hover.table-condensed.story-list 
    %th State 
    %th Remove 
0

您需要将表格移出%legend标记。

更改代码这样:

.form-box 
    %h3 Restrictions 
    %legend 
    Restricted Locations 
    = form_for [:blueadmin, :wine, @wine], html: {class: 'form-horizontal col-lg-2'} do |f| 
    %fieldset.inputs 
     .control-group 
     = f.label :us_states, "US States", class: 'control-label' 
     .controls 
      = f.collection_select :product, Restriction.all, :us_state, :us_state, {}, :multiple => 'true' 
    %fieldset 
     %ol 
     %li.button 
      = f.submit "Submit", class: 'btn btn-primary' 
    %table.table.table-hover.table-condensed.story-list 
    %th State 
    %th Remove 

仅使用,如果你有嵌套单一元素内嵌的内容。在你的情况你想窝Restricted Locations文本以及form

注: HAML工作压痕所以在不同的HTML代码或语法错误