Reputation: 1579
I am using the bootstrap-wysihtml5 gem, a WYSIWYG form text editor, for my app. When I enter something that looks like this into my text area:
"this is a test to see if bold and italic are working"
I see this in my view:
"this is a test to see if **bold** and *italic* are working"
Any html is shown as code instead of getting rendered as formatted text. It seems the formatting is getting coded, it's just not rendering correctly. What could be causing this?
My code is as below, and closely follows the ReadMe.
posts/_form.html.erb
<%= form_for @post, :html => { :multipart => true } do |f| %>
<%= f.label :content %>
<%= f.text_area :content, :class => 'wysihtml5' %>
<%= f.label :photo %>
<%= f.file_field :photo %>
<script type="text/javascript">
$('.wysihtml5').each(function(i, elem) {
$(elem).wysihtml5();
});
</script>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
posts/_post.html.erb
<div class="photo"><%= image_tag post.photo.url %></div>
<div class="content"><%= post.content %></div>
Upvotes: 2
Views: 333
Reputation: 1261
Try this in posts/_post.html.erb
<div class="content"><%= post.content.try(:html_safe) %></div>
Upvotes: 3
Reputation: 26131
<%= f.text_area :content, escape: => false, :class => 'wysihtml5' %>
Upvotes: 0
Reputation: 9691
Try changing it to <div class="content"><%= raw post.content %></div>
and see if it helps.
Upvotes: 1