Satchel
Satchel

Reputation: 16734

How do I put text and ruby code from link_to on the same line in haml?

I am trying to put a link_to between ( and ) by doing this:

= div_for review do
    = link_to review.title, review_path(review)
    (
    = link_to review.user.email, user_path(review.user)
    )

The outcome is not what I want because it puts spaces between the parenthesis and the link text, so it looks like:

 link1 ( link2 )

But I want it to look like:

 link1 (link2)

How do I do that using haml?

Upvotes: 1

Views: 4953

Answers (3)

Thilo
Thilo

Reputation: 17735

Use a string with inline ruby:

= link_to review.title, review_path(review)
=raw "(#{link_to review.user.email, user_path(review.user)})"

The raw is for Rails 3 (and higher) only.

Upvotes: 3

Sandvich
Sandvich

Reputation: 110

I recently fount interesting thing about haml

== - Ruby interpolated string

%h1== (#{link-to review.user.email, user_path(review.user)})

is like

%h1= raw "(#{link_to review.user.email, user_path(review.user)})"

Upvotes: 5

Dylan Markow
Dylan Markow

Reputation: 124469

= link_to review.title, review_path(review)
= surround '(', ')' do
  = link_to review.user.email, user_path(review.user)

Alternatively, you could put your link in a span tag and tell Haml to eat the whitespace:

(
%span>= link_to review.user.email, user_path(review.user)
)

Upvotes: 4

Related Questions