Nikita Barsukov
Nikita Barsukov

Reputation: 2984

Special characters in link_to

I would like to have a multiple sign '×' inside a link_to helper in my Rails 3 app.

Straightforward code <%= link_to '&times;', model, :confirm => 'Sure?', :method => :delete %> outputs &times;on my page. How to fix it?

Upvotes: 14

Views: 6367

Answers (1)

Scott
Scott

Reputation: 17247

To prevent your string from being "made safe" by Rails' output buffer:

<%= link_to '&times;'.html_safe, model, :confirm => 'Sure?', :method => :delete %>

Footnote

In my own pages, I encode everything as UTF-8, which means that I can use the real Unicode characters directly, rather than use the &...; code, but this probably isn't an option for you if you didn't start your project with that intent.

Upvotes: 34

Related Questions