2013-10-29 84 views
0

我與HAML不注入在正確的地方內容掙扎我想要的結果(初級),這裏是HAML的一部分:紅寶石HAML沒有得到

%div.form-group{:id => 'container'} 
- if [email protected]? 
    %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' 

的問題是, holderholder thick不在我的容器內,但在外面。爲什麼是這樣?我沒有正確調整什麼?

+1

縮進休息http://html2haml.heroku.com/ – apneadiving

+0

代替'%div.holder',使用'.holder',並用#container替換'%div.form-group {:id =>'container'}'。 form-group','%div.holder.thick'應該是'.holder.thick' – apneadiving

+0

http://haml2erb.herokuapp.com/ – apneadiving

回答

3

是的,if應該縮進,如果其內容是要進入#container

#container.form-group 
    - if [email protected]? 
    %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' 
0

如果你的容器%div.form-group那麼你只是爲了讓HAML明白它是股利,你的內容應該

內部,它會看起來像

%div.form-group{:id => 'container'} 
    - if [email protected]? 
    %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'