Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails: content submitted using ckeditor is displayed with html tags

I have text field where user would be writing recipe of food item. For formatting of text, I just install ckeditor.

Added gem "ckeditor" in gemfile and executed this:

   rails generate ckeditor:install --orm=active_record --backend=paperclip

as given in github.com/galetahub/ckeditor.

Then i updated my recipe text area to:

   <%= f.cktext_area :recipe, :size => 5, :id => "field-area5", :ckeditor => {:language => "us"}  %>

It displays all formatting tools and formats text properly. But when i submit the content and display the output using,

   <%= @product.recipe %>

it displays with HTML tags instead of the way i formatted. e.g.

  <p><strong>Recipe</strong></p> <h1><span style="font-family:georgia,serif"><em>i dont know anything</em></span></h1> 

Can anybody help why this is happening? How to display formatted content? Your help is appreciated.

Thanks.

like image 434
user2206724 Avatar asked Dec 03 '22 23:12

user2206724


1 Answers

Have you tried the following?

<%= raw(@product.recipe) %>

Take a look here for further info: http://api.rubyonrails.org/classes/ActionView/Helpers/OutputSafetyHelper.html#method-i-raw

like image 142
Mario Zigliotto Avatar answered Feb 16 '23 01:02

Mario Zigliotto