Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting HTML to content_tag in Ruby on Rails

How would you convert this HTML into the Rails content_tag helper syntax/format?

<p class="msg">
    <span class="strong">Most people enjoy the inferiority of their best friends.</span>
    <br>
    <span class="emphasize"> - Lord Chesterfield</span>
</p>
like image 242
keruilin Avatar asked Dec 27 '10 01:12

keruilin


2 Answers

to be precise with classes added. You can also use blocks with content_tags if you have a bunch of lines.

content_tag(:p, :class => 'msg') do
  content_tag(:span, "Most ... friends.", :class => "strong") +
  content_tag(:br) + 
  content_tag(:span, "- Lord .. ", :class => "emphasize")
end
like image 181
Aditya Sanghi Avatar answered Nov 05 '22 16:11

Aditya Sanghi


Is this what you're looking for?

content_tag(:p, content_tag(:span,  'Most people enjoy the inferiority of their best friends.') + '<br/>' + content_tag(:span, ' - Lord Chesterfield'))
like image 21
Jacob Relkin Avatar answered Nov 05 '22 18:11

Jacob Relkin