Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Using a combination of <a href="http://ruby-doc.org/core-2.0.0/String.html#method-i-strip" rel="nofollow"><code>strip</code></a> and the following <a href="http://ruby-doc.org/core-2.0.0/String.html#method-i-gsub" rel="nofollow"><code>gsub</code></a> regex match will render the following:</p> <pre><code>entry.text_body.strip.gsub(/\s+/, ' ') #=&gt; "To confirm your subscription to 'Blah ads. Location: Blah. Category: buy and # sell.', please click on the following link: https://domain.com/confirm/jBb62m # As we have no control over the content of the feeds we send, consider adding # email@domain.com to your address book or spam whitelist to placate any # overexcitable spam filters. If you weren't expecting to receive this email, # then simply ignore it and we'll go away." </code></pre> <p><strong>UPDATE</strong>:</p> <p>First, to replace the <code>\r\n</code> and <code>\n</code> newline characters with the HTML <code>&lt;br /&gt;</code> tag a your string, run the following <code>gsub</code> regex substitution:</p> <pre><code>'foo\r\nbar'.gsub(/(\r)?\n/, '&lt;br /&gt;') #=&gt; "foo&lt;br /&gt;bar" </code></pre> <p>As for the URL conversion to HTML: Rails used to have a view helper called <a href="http://apidock.com/rails/ActionView/Helpers/TextHelper/auto_link" rel="nofollow"><code>auto_link</code></a> which would automatically convert a URL to its fully valid markup equivalent. However, this feature has been <a href="https://github.com/rails/rails/commit/81cfbf4146d3c5a58054b64112b8ce196f2fc061" rel="nofollow">deprecated as of Rails 3.1</a>. Fortunately, the functionality was abstracted into a gem called <a href="https://github.com/tenderlove/rails_autolink" rel="nofollow">rails_autolink</a>.</p> <p>To install the gem, add the following to your Gemfile and run <code>bundle install</code>:</p> <pre><code># Gemfile gem 'rails_autolink' </code></pre> <p>Then, import the library (along with its core dependencies) into any script you want the <code>auto_link</code> functionality in:</p> <pre><code>include ActionView::Helpers::TextHelper include ActionView::Helpers::UrlHelper require 'rails_autolink' url = 'https://domain.com/confirm/jBb62m' auto_link(url) # Use auto_link(string).gsub(/\"/, '\'') to escape backslashes #=&gt; &lt;a href='https://domain.com/confirm/jBb62m'&gt;https://domain.com/confirm/jBb62m&lt;/a&gt; email = 'email@domain.com' auto_link(email) #=&gt; &lt;a href='mailto:email@domain.com'&gt;email@domain.com&lt;/a&gt; </code></pre> <p><strong>SUMMARY</strong>:</p> <pre><code>include ActionView::Helpers::TextHelper include ActionView::Helpers::UrlHelper require 'rails_autolink' auto_link(entry.text_body.gsub(/(\r)?\n/, '&lt;br /&gt;').strip.gsub(/\s+/, ' ')) #=&gt; "To confirm your subscription to 'Blah ads. Location: Blah. Category: buy # and sell.', please click on the following link:&lt;br /&gt;&lt;br /&gt;&lt;a # href=\"https://domain.com/confirm/jBb62m\"&gt;https://domain.com/confirm/jBb62m # &lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;As we have no control over the content of the feeds we # send, consider adding &lt;a href=\"mailto:email@domain.com\"&gt;email@domain.com&lt;/a&gt; # to your address book or spam whitelist to placate any overexcitable spam filters. # &lt;br /&gt;&lt;br /&gt;If you weren't expecting to receive this email, then simply ignore # it and we'll go away." </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

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