Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to have Rails Views process HTML tags from database content?

Ok. I know this is very basic. I want to have some basic tags around text content in the database to be processed in the view's rendering.

Basically, I have a model named Page.

rails g model Page name:string content:text 

I want whatever is in the content field to be shown in the view but, if there is HTML in the content field, I want it to be processed not just shown.

For example, in my Page#show view, I may have:

<%= @page.content %> 

Which outputs:

< p >This is my first < b >paragraph< /b >.< /p >

When I want it to output:

This is my first paragraph.

Again, please be gentle. I know this is probably pretty basic but I am having a hard time searching for how to do this. :)

like image 849
NJ. Avatar asked Jan 02 '11 18:01

NJ.


1 Answers

You can use the raw helper method.

<%=raw @page.content %>  
like image 75
Rob Di Marco Avatar answered Sep 28 '22 05:09

Rob Di Marco