Ruby on rails 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 => '' } %> {:icon=>';'}%> 这就是html中输出的内容 <a data-icon="&#xe61c;" href="/canvases/8">Preview</a> 对于工作的图标,这就是输
<%= link_to "Profile", current_user, :data => { :icon => '' } %>
{:icon=>';'}%>
这就是html中输出的内容
<a data-icon="&#xe61c;" href="/canvases/8">Preview</a>
对于工作的图标,这就是输出的内容(注意&现在是一个&)
看起来是这样的:
默认情况下,数据属性是HTML编码的。这可以防止。你可以把绳子标记为安全的
<%= link_to "Profile", current_user, :data => { :icon => ''.html_safe } %>
{:icon=>';'.html_safe}%>
这是硬编码字符串的查找。但请注意,如果使用用户提供的数据,可能会有危险。我是否使用用户提供的数据?对如果是,是否有其他解决方案?
<%= link_to "Profile", current_user, :data => { :icon => ''.html_safe } %>