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.
基本上,我有一个名为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.
我希望内容字段中的任何内容都显示在视图中,但是,如果内容字段中有HTML,我希望它不仅仅显示处理。
For example, in my Page#show view, I may have:
例如,在我的Page#show view中,我可能有:
<%= @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. :)
再次,请温柔。我知道这可能是非常基本但我很难找到如何做到这一点。 :)
2 个解决方案
#2
2
<%= @page.content.html_safe %>
if you are safe with it's content.
<%= @ page.content.html_safe%>如果您对内容安全。
#1
#2
2
<%= @page.content.html_safe %>
if you are safe with it's content.
<%= @ page.content.html_safe%>如果您对内容安全。