开发者

Rails: Create a Report System in Rails

i'm trying to adapt my messages system in order to be able to use it to send reports to users. For instance, a user might finish a job and he will then receive a private message as a report for that.

The problem is storing the report to my database. A report is not just text. It can have links, or even user generated data, that was previously stored in the db.

My idea was using render_to_strin开发者_StackOverflowg to render a view to a variable and then store it to the database as a new message. However, user generated data and links are a problem, because they are not escaped. Ideally, html tags like

should not be escaped, as well as link_to's. However, if there is a <%= user.username %> somewhere in the report, this one should be escaped.

I'm a bit stumbled with that. Do you know of an efficient way to do it ?


Generally anything that's in HTML mode you can escape with:

<%= h(user.username) %>

This is the simple "render safe HTML" helper method available to all views. Plain-text does not need to be escaped the same way.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜