سؤال

I have an column in database as welcome_emil of type TEXT.

I have saved the following code content saved in column as :

Thanks for Joining in!     \r\n\r\nYou can loginor refer your friends using your %referral_link%."

When i try to render this code into my email that is sent to the user. Complete content goes fine but

  \r\n\r\n

this is omitted and all text appear inline.

Here is the code that i use

  <%= p  @company.welcome_email.gsub('%referral_link%',@recipient.referral_link).html_safe %> 

Here is the screenshot how it looks like in email

enter image description here

هل كانت مفيدة؟

المحلول 3

I used GEM REDCARPET. Details here http://rubygems.org/gems/redcarpet.

And the following code works perfectly fine for me.

<% markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, :autolink => true, :space_after_headers => true) %>
<% welcome_email = @site.welcome_email.gsub('% referral_link%',@recipient. referral_link) %>
<%= markdown.render(welcome_email).html_safe %>    

Thanks.

نصائح أخرى

try this

     <%= @site.welcome_email.gsub(/\n/, '<br/>').html_safe %>

You can use rails's method simple_format which will convert line ending into <br> tags

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top