How do I get rid of the extra whitespace in html provided by Haml & Ruby?
I am trying to format a simple sentence that reads like this:
When my haml looks like this:
%a{:href => "link", :target=> '_blank'} x,
%a{:href => "link", :target=> '_blank'} y,
and
%a{:href => "link", :target=> '_blank'} z.
I get
When my haml looks a little different:
%a{:href => "link", :target=> '_blank'} x
,
%a{:href => "link", :target=> '_blank'} y
, and
%a{:href => "link", :target=> '_blank'} z
.
I get
... and the spaces don't look right.
How can I make it look the way I want it to?
I want him to look like
... with non-link commas and periods and no extra spaces.
+3
pixelfairy
source
to share
5 answers
Try this i hope it helps
= link_to "x", "Your-url", target: "_blank"
,
= link_to "y", "Your-url", target: "_blank"
= "and"
= link_to "z", "Your-url", target: "_blank"
0
Amit sharma
source
to share
You can also try this:
= "<a href='link' target='_blank'>x</a>, <a href='link' target='_blank'>y</a> and <a href='link' target='_blank'>z</a>".html_safe
0
Amit Badheka Pykih Staff
source
to share
Try to write a link like:
= ("#{link_to('x', 'link', target: '_blank')}, #{link_to('y', 'link', target: '_blank')}, and #{link_to('z', 'link', target: '_blank')}.").html_safe
Also you can replace the link to the link as root_path and it will work fine.
0
Alexander Belonogov
source
to share
I had similar problems, you could try
Helpers#succeed
eg.
= succeed ',' do
%a{:href=>"link"}x
= succeed ',' do
%a{:href=>"link"}y
0
SirLenz0rlot
source
to share
EDIT due to my misunderstanding, I gave you the wrong solution, this might be what you need:
You must use
success
from haml helper:
= succeed ',' do
%a{:href => "link", :target=> '_blank'}x
= succeed ',' do
%a{:href => "link", :target=> '_blank'}y
= succeed '.' do
%a{:href => "link", :target=> '_blank'}z
-1
teoreda
source
to share