2017-11-10 1 views
0

したがって、この.erbコードを使用して、.hamlに変換します。 (一部はHAMLが高速であると言い、私は私はまだ学習曲線内struglingていると思う;))haml 2番目のクラスとしてのpull-rightは、その後に続く場合には機能しません。

<div class="row"> 
    <div class="col-md-12"> 
    <ul class="list-inline pull-right"> 
     <% if current_page?(webservices_path) %> 
     <li class="submenu_links_current"> 
     <% else %> 
     <li class="submenu_links"> 
     <% end %> 
     <%= link_to webservices_path do %> 
      <i class="fa fa-home" aria-hidden="true" style="color: white;"></i> 
      Webservices 
     <% end %> 
     </li> 
    </ul> 
    </div> 
</div> 

は、私は気圧持って最寄りのHAML翻訳:

.row 
    .col-md-12 
    %ul.list-inline.pull-right 
    - if current_page?(webservices_path) 
     %li.submenu_links_current 
     = link_to webservices_path do 
      %i.fa.fa-home{"aria-hidden" => "true", "style" => "color: white;"} 
      Webservices 
    - else 
     %li.submenu_links 
     = link_to webservices_path do 
      %i.fa.fa-home{"aria-hidden" => "true", "style" => "color: white;"} 
      Webservices 

私はこのHAMLを持つ2つの問題を抱えていますたった今。

。ulとliの間にif文がある場合、ulにはプル右が適用されません。

また、現在のwebservices_pathにlink_to webservices_pathが表示されていないので、このコード化された次のコードは機能しません。

.row 
    .col-md-12 
    %ul.list-inline.pull-right 
    - if current_page?(webservices_path) 
     %li.submenu_links_current 
    - else 
     %li.submenu_links 
     = link_to webservices_path do 
      %i.fa.fa-home{"aria-hidden" => "true", "style" => "color: white;"} 
      Webservices 

ありがとうございます!私はあなたがこのような何かしたいと思います

答えて

0

.row 
    .col-md-12 
    %ul.list-inline.pull-right 
     %li{:class => (current_page?(webservices_path) ? 'submenu_links_current' : 'submenu_links')} 
     = link_to webservices_path do 
      %i.fa.fa-home{"aria-hidden" => "true", "style" => "color: white;"} 
      Webservices 

注2 liは、ハッシュのclass要素ではなく、ドット構文を使用してクラスを設定し、単一の要素に統合されています。これにより、複製が削除され、link_toが削除されます。また、ulの下に字下げされています(コード内にはifの文が同じレベルにあるので、liはその子ではありません)。

+0

ありがとう@matt。期待どおりに働く。明確な説明;) –

関連する問題