#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2007
    Location
    Glendale AZ
    Posts
    230
    Rep Power
    96

    new line to <br>


    Hopefully, this is easier than my last question that has a lot of views but no replies

    I have this <%= web_set.comment %> which outputs user entered content back onto the screen and into an email. It is stripping all new lines and carriage returns making the input difficult to read as one enormous paragraph and/or run on sentence.

    I've done my googling and found an option but I'm not sure how to implement it since I don't know much about Ruby

    mystring.gsub(/(?:\n\r?|\r\n?)/, '<br>')

    I think I might be able to say <%= web_set.comment.gsub(/(?:\n\r?|\r\n?)/, '<br>') but I may have to perform the function before I output it?

    Thoughts?

    Mike
  2. #2
  3. Lord of the Dance
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Oct 2003
    Posts
    4,131
    Rep Power
    2011
    When I looked at this first time, I thought it was mostly a question regarding the use of regular expression.

    Originally Posted by big0mike
    I think I might be able to say <%= web_set.comment.gsub(/(?:\n\r?|\r\n?)/, '<br>') but I may have to perform the function before I output it?
    One good thumb rule, when you find some code on-line, is to test it and see what happen.

    Have you looked at the manual for gsub? Looks like you should be able to use directly, as it return the result you want.
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2007
    Location
    Glendale AZ
    Posts
    230
    Rep Power
    96
    Originally Posted by MrFujin
    One good thumb rule, when you find some code on-line, is to test it and see what happen.
    Normally, I would, but I don't have a test environment so I've been playing with pages after hours when our customers would never be online. We're a small printshop so if it's after hours locally it's rare that anyone will be accessing the site.

    Originally Posted by MrFujin
    Have you looked at the manual for gsub? Looks like you should be able to use directly, as it return the result you want.
    No, I didn't even get that far yet... Looks like I can use it directly, though.

    Thanks.
  6. #4
  7. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2007
    Location
    Glendale AZ
    Posts
    230
    Rep Power
    96
    Finally got a chance to try this and it worked, kinda. Wound up with:

    Lorem Ipsum <br> Lorem Ipsum <br> Lorem Ipsum

    instead of

    Lorem Ipsum
    Lorem Ipsum
    Lorem Ipsum

  8. #5
  9. Lord of the Dance
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Oct 2003
    Posts
    4,131
    Rep Power
    2011
    do you want to have a text-based new-line or an html-based new line?

    What if you try this:
    Code:
    mystring.gsub(/(?:\n\r?|\r\n?)/, '\n<br>')
    not sure if \r should be included, but you can always test it with or without.
  10. #6
  11. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2007
    Location
    Glendale AZ
    Posts
    230
    Rep Power
    96
    Originally Posted by MrFujin
    do you want to have a text-based new-line or an html-based new line?

    What if you try this:
    Code:
    mystring.gsub(/(?:\n\r?|\r\n?)/, '\n<br>')
    not sure if \r should be included, but you can always test it with or without.
    Not sure what you mean by text-based v html-based. The form returns an HTML page and sends an HTML email. So wherever they type a ENTER, which is usually \n\r, it should insert a <br> so the following text will be on the next line.

    It appears, since it's inserting <br> and outputing it as text, that the RoR output is just treating it as text and not a BREAK character. So, it seems likely that changing '<br>' to '\n<br>' would simply output Lorum Ipsum \n<br> Lorem Ipsum.

    When I get some more time I'll play with it some more...
  12. #7
  13. Lord of the Dance
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Oct 2003
    Posts
    4,131
    Rep Power
    2011
    If you have issue with how the email is formatted, you should post the code relevant for that part.
  14. #8
  15. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2007
    Location
    Glendale AZ
    Posts
    230
    Rep Power
    96
    Couldn't tell you where that (those) files are. Since I'm just mucking around way over my head and the whole MVC thing I still don't grasp.

    There are two files in a directory called "order_mailer" that I would think should have something to do with it.

    Code:
    <style type="text/css">
    <%= File.open("public/stylesheets/reset.css").readlines.join(' ').html_safe %>
    </style>
    <% @content = render(@web_order) %>
    <%= yield :head %>
    <%= @content %>
    Code:
    <style type="text/css">
    <%= File.open("public/stylesheets/reset.css").readlines.join(' ').html_safe %>
    </style>
    <style type="text/css" media="print">
      .no-print { display: none; }
    </style>
    <% @content = render(@web_order, :dealer_copy => true) %>
    <%= yield :head %>
    <a class="no-print" href="http://<%= SiteConfig['site.domain'] %>/user/web_orders/<%= @web_order.id %>"> Having trouble reading this email? Click here. </a>
    <%= @content %>
    I see an ".html_safe" in both of them which makes me wonder but both uses are in reference to the stylesheet so how can it be affecting the content of the page?

IMN logo majestic logo threadwatch logo seochat tools logo