John Smith John Smith - 3 months ago 10x
Ruby Question

How to change href in HAML if statement

I have 2 different paths that my

holds, and they both path to the same place. I want them to path differently. Here's my code:

%table.table-base.table-striped.table-hover{:id => "work-list-table"}
- @work_list.each do |workList| //there are two items in this object
%tr{: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

As you can see, the two items I have both path to duplicate_claims_work_lists_path. I want to change the href to path to
. Can I change it in the if statement?


It would be better to assign the url to a variable, then use that in the tr element

- @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 =>,href: url, :style => "cursor:pointer", :onclick=>"workListTrActions(this)"}