Reputation: 430
i have created in my application_helper a define for a standard link_to like this:
module ApplicationHelper
def foo_link_to(text, path)
out = "<span class=\"span\">"
out += link_to text, path
out += "</span>"
out
end
end
and in my partial i have
<%= foo_link_to 'text', home_path %>
but this is my output
<span class="span"><a href="/home">index</a></span>
now, my question is: where i need to insert the html_escape?
ty all
Thanks at all for the support. Now i have another issue...if i wont this output what i have to do?
<a href="home.html"><i class="iclass"></i><span class="span"> text </span></a>
Using raw out
and out.html_safe
the output is
a href="/home">/home</a><span class="span"><i class="iclass">text</i></span>
Upvotes: 0
Views: 270
Reputation: 24815
Use raw
, in your last line
raw out
And your helper can be further refactored as
def foo_link_to(text, path)
content_tag :span do
link_to text, path
end
end
I forget but it seems you don't need raw
in the later case.
Update: For the last icon one, you can output like this
link_to 'home.html' do
content_tag :i, class: 'iclass'
content_tag :span, class: 'span' do
'Text'
end
end
Upvotes: 2
Reputation: 5998
I think it should be
module ApplicationHelper
def foo_link_to(text, path)
out = "<span class=\"span\">"
out += link_to text, path
out += "</span>"
out.html_safe
end
end
Upvotes: 1