Rails 删除了 target="_blank" [英] Rails removes target="_blank"
问题描述
我在 rails 4.1.4 上有一个简单的博客应用程序,它允许用户创建帖子.每当用户在他们的帖子中添加链接时,rails 都会删除 target="_blank" 标签.例如:
I have a simple blog application on rails 4.1.4 that allows users to create posts. Whenever a user adds a link in their post, the target="_blank" tag is removed by rails. For example:
用户输入:
<a href="www.google.com" target="_blank">Google</a>
查看创建帖子的来源时:
When viewing source of the created post:
<a href="www.google.com">Google</a>
显示.
我在这里遗漏了什么明显的东西吗?为什么目标属性会被 rails 移除?
Am I missing something obvious here? Why is the target attribute being removed by rails?
推荐答案
Rails 默认清理输出,目标属性是默认被剥离的属性之一.您可以使用以下内容将目标属性列入白名单:
Rails sanitizes output by default, and the target attribute is one of the attributes that gets stripped out by default. You can white list the target attribute with something like:
<%= 清理 html.body,属性:%w(href target) %>
更多信息:http://api.rubyonrails.org/classes/ActionView/Helpers/SanitizeHelper.html
这篇关于Rails 删除了 target="_blank"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!