如何在HAML if语句中更改href

时间:2016-07-08 15:38:36

标签: ruby-on-rails ruby haml

我的workList拥有两条不同的路径,它们都路径到同一个地方。我希望他们以不同的方式前进。这是我的代码:

%table.table-base.table-striped.table-hover{:id => "work-list-table"}
  %tbody
    - @work_list.each do |workList| //there are two items in this object
      %tr{:id => workList.id,href: duplicate_claims_work_lists_path, :style => "cursor:pointer", :onclick=>"workListTrActions(this)"}
      -if workList.work_list_name == "Provider Payments"
           //href = provider_payments_work_lists_path
        %td
          %ul.custom-ul
            %li
              %h4
                =workList.work_list_name

正如您所看到的,这两个项目我都有duplicate_claims_work_lists_path的路径。我想将href更改为provider_payments_work_lists_path的路径。我可以在if语句中更改它吗?

1 个答案:

答案 0 :(得分:2)

最好将url分配给变量,然后在tr元素中使用它

- @work_list.each do |workList| //there are two items in this object
  - url = (workList.work_list_name == "Provider Payments") ? provider_payments_work_lists_path : duplicate_claims_work_lists_path
  %tr{:id => workList.id,href: url, :style => "cursor:pointer", :onclick=>"workListTrActions(this)"}