james
james

Reputation: 525

How to use HTML5 Entities in Rails 4 Helper Tags

I've been trying to use cdata_section, content_tag, escape_once and tag from the tag helper on rails to make the "X" appear from ✖

<%= link_to( ("&#x2716;"), url_options = {:base_rate_id => rates.id}, class: "button tiny" ) %

no luck with the different methods. it either displays nil or the raw literal "&#x2716"; is there better way?

Upvotes: 0

Views: 162

Answers (3)

Slicedpan
Slicedpan

Reputation: 5015

You can use the following syntax

<%= link_to("&#x2716;".html_safe, url_options = {:base_rate_id => rates.id}, class: "button tiny") %>

However you should be careful using html_safe. Ensure that no user provided input makes its way into a string rendered using it.

Upvotes: 1

Rajarshi Das
Rajarshi Das

Reputation: 12320

Use ActionView::Helpers::SanitizeHelper

<%= link_to( sanitize("&#x2716;"), url_options = {:base_rate_id => rates.id}, class: "button tiny" ) %>

Upvotes: 1

RAJ
RAJ

Reputation: 9747

You just need to un-escape HTML entities as follow:

<%= link_to(CGI.unescapeHTML("&#x2716;"), url_options = {:base_rate_id => rates.id}, class: "button tiny" ) %>

P.S.: May be you need to include the CGI library:

require 'cgi'

Upvotes: 1

Related Questions