John Smith John Smith - 4 months ago 12
Ruby Question

How to change href in HAML if statement

I have 2 different paths that my

workList
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"}
%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


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
provider_payments_work_lists_path
. Can I change it in the if statement?

Answer

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