How do I remove the html tags from rails_admin/ckeditor so that field content does not contain html tags?

StackOverflow https://stackoverflow.com/questions/18776714

Question

I'm using rails_admin in order to create wysiwyg editor for my Post model, which are essentially just blog posts. I have a content field and title field.

I've also included ckeditor in order to format the text of the content field. I'm trying to display each post in my view like so:

<% @posts.each do |post| %>
  <div class="row text">
   <%= post.title %>
   <%= post.content %>
  </div>
<% end %>

However, when displayed on the screen the content prints out all of the html tags that were added to the content by ckeditor. For example, if I increased the size of the text, or made a sentence bold or italic, it will print out all of the html and css code.

I'm hoping there is away to get the html to render to my erb files so that it is formatted automatically in the view for the user.

When I look in inspector the content is surrounded in quotes.

My railsadmin config file calls the Post model as such:

config.model Post do
  edit do
    field :title
    field :content, :ck_editor
  end
end

Thank you.

Was it helpful?

Solution

So, as far as I could gather, you want to display the actual unescaped HTML.

<%= raw post.content %>

Reference: raw (ActionView::Helpers::OutputSafetyHelper) - APIdock

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top