0

我正在努力解决 haml 没有在正确的位置注入内容,这是 haml 的一部分:

%div.form-group{:id => 'container'}
- if !@data.nil?
  %p= t('users.data_name')
  = link_to t('users.delete'), 'javascript:void(0)', :class => 'delete', :data => {:id => @data.id}
  %div.holder.thick
    = image_tag @data.path
- else
  = link_to t('users.upload'), 'javascript:void(0)', :class => 'btn btn-large'
  %div.holder
    = image_tag '/assets/missing_image.png'

问题是holderorholder thick不在我的容器内而是在外面。为什么是这样?我没有正确对齐什么?

4

2 回答 2

3

是的,if如果它的内容要进入 . 应该缩进#container

#container.form-group
  - if !@data.nil?
    %p= t('users.data_name')
    = link_to t('users.delete'), 'javascript:void(0)', :class => 'delete', :data => {:id => @data.id}
    .holder.thick
      = image_tag @data.path
  - else
    = link_to t('users.upload'), 'javascript:void(0)', :class => 'btn btn-large'
    .holder
      = image_tag '/assets/missing_image.png'
于 2013-10-29T08:30:13.267 回答
0

如果您的容器是,%div.form-group那么您只需缩进其余部分,以便 haml 了解您的内容应该在该 div 内

所以它看起来像这样

%div.form-group{:id => 'container'}
  - if !@data.nil?
    %p= t('users.data_name')
    = link_to t('users.delete'), 'javascript:void(0)', :class => 'delete', :data => {:id => @data.id}
    %div.holder.thick
      = image_tag @data.path
  - else
    = link_to t('users.upload'), 'javascript:void(0)', :class => 'btn btn-large'
    %div.holder
      = image_tag '/assets/missing_image.png'
于 2013-10-29T08:33:46.340 回答