Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

2 haml link_to on the same line

I have the haml code template as below:

%td= link_to "Enable", enable_product(@product)
%td= link_to 'Disable', disable_product(@product)

And it display like

Enable

Disable

But it display in two cell of the table. What I want to display is to put it into 1 cell only. Like

Enable/Disable Product

Apparently, I still want to get the hyperlink under Enable and Disable.

How I can do that in Haml?

Thank you!

like image 978
AgainstPIT Avatar asked May 29 '13 07:05

AgainstPIT


2 Answers

The concatenation tip is all good.

Just for the record, here's another method, using HAML's whitespace removal:

%td
  %span>
    = link_to "Enable", "#"
  \/
  %span>
    = link_to "Disable", "#"

The > "eats" the whitespace around the span tags.

Why do we need the spans? Because HAML's whitespace removal only works on actual HAML tags, not on strings coming from Ruby.

like image 60
Jesper Avatar answered Nov 03 '22 21:11

Jesper


As link_to produces a string, you can concatenate them:

%td= link_to("Enable", enable_product(@product))+'/'+link_to('Disable', disable_product(@product))

maybe you have to declare the result as html_safe:

%td= (link_to("Enable", enable_product(@product))+'/'+link_to('Disable', disable_product(@product))).html_safe
like image 3
Martin M Avatar answered Nov 03 '22 20:11

Martin M