3 Replies - 874 Views - Last Post: 11 November 2010 - 02:24 PM Rate Topic: -----

#1 nimajneb  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 11
  • View blog
  • Posts: 116
  • Joined: 04-August 10

Submitted Text is in Plaintext and not HTML

Posted 11 November 2010 - 01:01 PM

I'm creating a simple site where a user submits information in a text area and it shows up on another page. However, it seems as though if there is any html tags in the post, they show up as plain text in the post and not as html. Whats the way to fix this?

Here is how it is displayed on the page:

Quote

Ruby on Rails

Test page for a "Ruby on Rails" knode... <u><h3>Links</h3></u> <br> <a href="http://mislav.uniqpath.com/poignant-guide/book/">Why's (poignant) Guide to Ruby</a>

Cat: Programming

Tag: ruby, rails,


the source for the text is:

<p>
   <h1>Ruby on Rails</h1>
</p>

<p>
  Test page for a &quot;Ruby on Rails&quot; knode...

&lt;u&gt;&lt;h3&gt;Links&lt;/h3&gt;&lt;/u&gt;

&lt;br&gt;
&lt;a href=&quot;http://mislav.uniqpath.com/poignant-guide/book/&quot;&gt;Why's (poignant) Guide to Ruby&lt;/a&gt;

</p>

<p>
  <b>Cat:</b>
  Programming
</p>

<p>
  <b>Tag:</b>
  ruby, rails, 
</p>





Should I be looking at a parser or something?

Is This A Good Question/Topic? 0
  • +

Replies To: Submitted Text is in Plaintext and not HTML

#2 The Neoracle  Icon User is offline

  • Check, check, 1, 2.
  • member icon

Reputation: 21
  • View blog
  • Posts: 4,097
  • Joined: 30-March 01

Re: Submitted Text is in Plaintext and not HTML

Posted 11 November 2010 - 01:04 PM

Rails is escaping the HTML by default for security reasons. Letting someone submit html and printing it out on another page is such a bad idea, I'm not going to link you to how to make rails not escape it.
Was This Post Helpful? 0
  • +
  • -

#3 nimajneb  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 11
  • View blog
  • Posts: 116
  • Joined: 04-August 10

Re: Submitted Text is in Plaintext and not HTML

Posted 11 November 2010 - 01:07 PM

Well hell. I can use sanitize on it so that only certain html goes through if it makes you happy. But I need html to be able to be submitted for this.
Was This Post Helpful? 0
  • +
  • -

#4 nimajneb  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 11
  • View blog
  • Posts: 116
  • Joined: 04-August 10

Re: Submitted Text is in Plaintext and not HTML

Posted 11 November 2010 - 02:24 PM

To answer my own question on here. Rails automatically escapes html tags on a post. to remove the escaped characters, simply append ".html_safe"

ie.

<%= '<a href="http://google.com">2</a>'.html_safe %>



Thanks for all the "help"
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1