Andrew Cetinic
Andrew Cetinic

Reputation: 2835

Rails 3 link_to inside a string

Everytime I am trying to combine a string with a link_to it is outputting in my browser as escaped HTML.

eg.

%(TEST #{link_to(object.title, object)})

OUTPUTS

TEST <a href="/objects/3">TEST OBJECT</a> 

Why is this happening ? Every example I see on net the link_to does not get escaped.

Upvotes: 3

Views: 4957

Answers (2)

rkleine15
rkleine15

Reputation: 147

This also do the job:

<%=raw %(TEST #{link_to(object.title, object)}) %>

Upvotes: 4

Mischa
Mischa

Reputation: 43318

Output is escaped by default in Rails 3. If you append .html_safe to your string it will do what you expect.

%(TEST #{link_to(object.title, object)}).html_safe

Upvotes: 12

Related Questions