Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6732455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:39:12+00:00 2026-05-26T10:39:12+00:00

Here is the exact string that is stored in the db: @blog_post.content = <p><img

  • 0

Here is the exact string that is stored in the db:

@blog_post.content = "<p><img src=\"http://localhost:3000/assets/sa_clubbing_logo.png\" alt=\"Sa_clubbing_logo\"><div><b>An image</b></div><div><b><br></b></div><div><b>Another image</b></div><div><b><img src=\"http://localhost:3000/assets/sa_clubbing_logo.png\" alt=\"Sa_clubbing_logo\"><br></b></div></p>" 

as you can see. It is made up of a few images and some bold text.

Ok, so I have html saved in the db. I am trying to append the html to a content editable div (my rich text editor) like this.

  $(document).ready(function(){  

  $('#rte').append("<%= @blog_post.content %>");

  });

It is showing up in my content editable div, but as actual text. I want it to be rendered as html so the images are actually showing. It seems like the html that is being appended is this:

<p>&lt;p&gt;&lt;img src="http://localhost:3000/assets/sa_clubbing_logo.png" alt="Sa_clubbing_logo"&gt;&lt;div&gt;&lt;b&gt;An image&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Another image&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;img src="http://localhost:3000/assets/sa_clubbing_logo.png" alt="Sa_clubbing_logo"&gt;&lt;br&gt;&lt;/b&gt;&lt;/div&gt;&lt;/p&gt;</p>

So I tried putting the string into the append method manually and I got exactly what I wanted:

  $(document).ready(function(){  

  $('#rte').append("<p><img src=\"http://localhost:3000/assets/sa_clubbing_logo.png\" alt=\"Sa_clubbing_logo\"><div><b>An image</b></div><div><b><br></b></div><div><b>Another image</b></div><div><b><img src=\"http://localhost:3000/assets/sa_clubbing_logo.png\" alt=\"Sa_clubbing_logo\"><br></b></div></p>");

  }); 

The html being appended here is this:

<p><img src="http://localhost:3000/assets/sa_clubbing_logo.png" alt="Sa_clubbing_logo"></p><div><b>An image</b></div><div><b><br></b></div><div><b>Another image</b></div><div><b><img src="http://localhost:3000/assets/sa_clubbing_logo.png" alt="Sa_clubbing_logo"><br></b></div><p></p>

The images are showing up in my editor just the way I imagined they should.

Why does this work when I insert the string manually, but not when I use <%= @blog_posts.content %> ?

I must be missing some sort of formatting issue here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T10:39:12+00:00Added an answer on May 26, 2026 at 10:39 am

    Replace:

    <%= @blog_post.content %>
    

    With:

    <%=raw @blog_post.content %>
    

    Or:

    <%== @blog_post.content %>
    

    Or even:

    <%= @blog_post.content.html_safe %>
    

    Explanation:

    Rails protects you by default so you have to tell when you consider html safe.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this exact question was asked here , but the answer didn't work
Here's my situation. I have followed the exact instructions on wordpress codex page about
Alright, hard to phrase an exact title for this question, but here goes... I
Here's the deal: I'm in the process of planning a mid-sized business application that
I have a SqlCommand which runs a stored procedure that contains two integer output
I've got a C# string extension that really makes life easy, but I am
UPDATE As Mathias notes below, this exact problem has been reported and resolved here:
I guess this question that would have already been asked here. I searched but
I'm trying to store a complex object here and am doing that by serialising
I have access to some images that can be gathered like this: http://www.example.com/imageGetter.php?a=0001 If

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.