LoginSignup
21
20

More than 5 years have passed since last update.

Hamlで条件に合わせてclassを追加する方法

Posted at

rails&hamlで、ナビゲーションメニューのclassにactiveをつける方法です(rails4.0.2, haml4.1.0を使用)

  %h3 Menu
  %ul
    %li{:class => current_page?(root_path) && "active"}
      %a ホーム
    %li{:class => current_page?(next_path) && "active"} 
      %a 次のページ

ちなみに以下のような書き方も可能です。

  %li{:class => #"{ 'active' if current_page?(root_path) }" }
21
20
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
21
20