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:

want

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

undesired link on comma

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

enter image description here

... 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

want

... with non-link commas and periods and no extra spaces.

+3


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


source


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


source


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


source


I had similar problems, you could try Helpers#succeed

eg.

= succeed ',' do
  %a{:href=>"link"}x
= succeed ',' do
  %a{:href=>"link"}y

      

0


source


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


source







All Articles