Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I tell Rails/HAML to not escape a URL?
    text
    copied!<p>I have this code: </p> <pre><code>= link_to "unsubscribe instantly", "*|UNSUB|*".html_safe </code></pre> <p>That generates this HTML:</p> <pre><code>&lt;a href="*%7CUNSUB%7C*"&gt;unsubscribe instantly&lt;/a&gt; </code></pre> <p>The | characters are escaped. That won't work, as I'm sending this HTML to a service that is supposed to replace <code>*|UNSUB|*</code> with an unsubscribe url.</p> <p>Instead, I want Rails/HAML to generate this:</p> <pre><code>&lt;a href="*|UNSUB|*"&gt;unsubscribe instantly&lt;/a&gt; </code></pre> <hr> <p>I went to <a href="http://haml-lang.com/try.html" rel="nofollow noreferrer">http://haml-lang.com/try.html</a> and entered <code>%a{:href => "*|UNSUB|*"} unsubscribe</code> and the output was what I was expecting. So I'm guessing this is a Rails thing.</p> <hr> <p><b>UPDATE</b>: I tried this on a new Rails 3.1 application and the pipes aren't being escaped -- which is what I wanted. There's something weird happening with my main rails application that's causing the URLs to be escaped -- looking into it further now.</p> <p><hr> <b>UPDATE</b>: I figured it out. I had some Rack middleware that was running something like:</p> <pre><code>content = Nokogiri(response) # ... processing return content.to_html </code></pre> <p>This was encoding the stuff inside the URLs. I asked a related question here: <a href="https://stackoverflow.com/questions/8512972/preventing-nokogiri-from-escaping-characters-in-urls">Preventing Nokogiri from escaping characters in URLs</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload