开发者

Embedded HTML code being displayed rather than HTML being rendered

I am trying to use the calendar gem in my project (https://github.com/elevation/event_calendar). But when I open the calendar page, it renders the page by showing the html code of the calendar rather than 开发者_Python百科rendering the html. Basically the source for the page generate is like <div class="ec-calendar"> instead of . Can anyone let me know what is going on and how to resolve it.


I assume you are using Rails 3? As a security measure against XSS (Cross Site Scripting), Rails 3 renders html inside of strings as text. If you know the html in your string is safe, call html_safe on it, like

'<div class="ec-calendar">'.html_safe

or

raw '<div class="ec-calendar">'

html_safe I believe, is preferred over raw. Not sure what's different behind the scenes, if anything.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜