Reputation: 401
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!
Upvotes: 6
Views: 2465
Reputation: 4555
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.
Upvotes: 6
Reputation: 8668
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
Upvotes: 3