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 开发者_JAVA技巧do that using haml?
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)})"
= 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)
)
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.
精彩评论