开发者

Want to allow inserting html into textarea, but hide html formatting when showing a list

I am creating a simple CMS, and I want the admin to be able to insert HTML into the textarea and save the article to the db.

And when I display the article, I want to render the html markup/formatting for the article.

BUT, when I am showing a summary of articles, I show the title and a little blurb, how can I escape the HTML formatting in the article body when showing a summary?

I开发者_开发问答 am currently doing:

<%= trim(article.body, :length => 100) %>

I tried adding h but that didn't work?


Are you using rails 3?

If so, h is applied by default now, so use .html_safe to get unescaped text. See here: http://markconnell.co.uk/posts/2010/02/rails-3-html-escaping


strip_tags might help as it did in my case.

<%= trim(strip_tags(article.body), :length => 100) %>


Try using Javascript's InnerHTML function < script>
function change(){ document.getElementById("Show_Results").innerHTML = "here is html;
}
< /script>
< p onclick="change()" id="Show_Reults">Hey

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜