Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails将数据属性输出为文本_Ruby On Rails_Ruby On Rails 4 - Fatal编程技术网

Ruby on rails Rails将数据属性输出为文本

Ruby on rails Rails将数据属性输出为文本,ruby-on-rails,ruby-on-rails-4,Ruby On Rails,Ruby On Rails 4,我正在尝试使用数据属性向链接添加字体图标 这是我的rails模板 <%= link_to "Profile", current_user, :data => { :icon => '&#xe609;' } %> {:icon=>';'}%> 这就是html中输出的内容 <a data-icon="&amp;#xe61c;" href="/canvases/8">Preview</a> 对于工作的图标,这就是输

我正在尝试使用数据属性向链接添加字体图标

这是我的rails模板

<%= link_to "Profile", current_user, :data => { :icon => '&#xe609;' } %>
{:icon=>';'}%>
这就是html中输出的内容

<a data-icon="&amp;#xe61c;" href="/canvases/8">Preview</a>

对于工作的图标,这就是输出的内容(注意&现在是一个&)


看起来是这样的:


默认情况下,数据属性是HTML编码的。这可以防止。你可以把绳子标记为安全的

<%= link_to "Profile", current_user, :data => { :icon => '&#xe609;'.html_safe } %>
{:icon=>';'.html_safe}%>

这是硬编码字符串的查找。但请注意,如果使用用户提供的数据,可能会有危险。

我是否使用用户提供的数据?对如果是,是否有其他解决方案?
<%= link_to "Profile", current_user, :data => { :icon => '&#xe609;'.html_safe } %>