0

我是网络开发新手。下面我有一个haml代码

%th
    %a#title_header
        %a{:th => ("hilite" if @sort == "title")}= link_to 'Movie Title', :sort => "title"

这给了我以下 HTML

<th>
   <a id='title_header'>
       <a th='hilite'><a href="/movies?sort=title">Movie Title</a></a>
   </a>
</th>

虽然我想要得到的是

<th class='hilite'>
    <a id='title_header'><a href="/movies?sort=title">Movie Title</a></a>
</th>
4

2 回答 2

1

这与我的回答非常相似:Add dynamic attributes to HAML tag using helper method in rails

在你的情况下,它应该是这样的:

%th{:class => if @sort == 'title' then 'hilite' end}
    %a#title_header
        %a= link_to 'Movie Title', :sort => "title
于 2012-10-20T18:57:50.733 回答
1
%th.hilite
  %a#title_header
    %a{:href => "/movies?sort=title"} Movie Title

顺便说一下,有一个名为http://html2haml.heroku.com/的项目,看看吧!

于 2012-10-20T18:31:07.193 回答