Rails:如何显示与www.example.com的链接,但不显示使用Google Ajax API解析的<a> tag

时间:2017-11-04 21:56:18

标签: ruby-on-rails ruby

Using auto_link gem when a user write www.google.com the view generate a link. But also if user write <a href="www.google.com"> the view generate a link.

Simply, I want that <a> tag doesn't generate link, but only www.example.com. (like Facebook, twitter etc..., if you write <a> tag doesn't generate a link.

Is possibile to generate link only with www.example.com method? And if user write <a href="www.google.com"> generate a simply string <a href="www.google.com"> and not a link.

1 个答案:

答案 0 :(得分:0)

在将字符串传递给生成链接的方法之前,您可以先尝试HTML转义字符串。

这样的事可能适合你:

<%= auto_link(html_escape(user_generated_content)) %>

或更短:

<%= auto_link(h(user_generated_content)) %>