Godzilla74
Godzilla74

Reputation: 2502

Active Admin not parsing html correctly

I'm creating a blog with rails using activeadmin and active_admin_editor. The Blog table is simple:

title:string
content:text

When I add a blog post it shows the html tags, I need the tags to actually be parsed so blog posts actually look like a real html page.

I've also already tried a migration to change the content column to 'text' instead of a string... that didn't help.

This is what my posts look like right now: enter image description here

What have I done wrong or missed here to get the html tags to render correctly?

** UPDATE ** After a suggestion to get the activeadmin view working, I'm still left with the raw html in the user view (non-admin user that can only view the blog)

enter image description here

Upvotes: 0

Views: 3265

Answers (2)

rorykoehler
rorykoehler

Reputation: 1702

The correct answer here, which I found looking for a solution, is outdated now. The following code should get you there instead:

ActiveAdmin.register Post do
  # ....
  index do
    # ...
    column :content do |post| 
      raw(post.content)
    end
    # ...
  end
  show do
    # ...
    row :content do |post| 
      raw(post.content)
    end
    # ...
  end
end

Upvotes: 0

Martin
Martin

Reputation: 7714

You can customize the ActiveAdmin pages into admin/post.rb with something like:

ActiveAdmin.register Post do
  # ....
  index do
    # ...
    column (:content) { |post| raw(post.content) }
    # ...
  end
  show do
    # ...
    row (:content) { |post| raw(post.content) }
    # ...
  end
end

For your own views (ex: posts/show.html.erb), just use:

raw(@post.content)

instead of

@post.content

in your own view. 'raw' will show the content "as is", without escaping the HTML (which Rails is doing by default).

Upvotes: 7

Related Questions