简体   繁体   English

Ruby on Rails simple_format限制

[英]Ruby on Rails simple_format restrictions

I'm using Rail's simple_format to take in details from a user. 我正在使用Rail的simple_format来接受用户的详细信息。 I want them to be able to add paragraphs, line breaks, paragraphs, anchor tags, etc. but I want to restrict some HTML tags–specifically images. 我希望他们能够添加段落,换行符,段落,锚标记等。但是我想限制一些HTML标记-特别是图像。

Does anyone know how I could implement this? 有人知道我该怎么实现吗?

Also, I've looked at the documentation but I can't seem to find which HTML tags are allowed using simple_format . 另外,我查看了文档,但似乎找不到使用simple_format允许使用的HTML标签。 Is anyone aware of a list somewhere? 有人知道某处的清单吗?

You can use sanitize helper built in rails: 您可以使用内置rails的sanitize助手:

sanitize(html, tags: %w(a b i u strong em img p br)

It will allow only specific set of tags. 它将仅允许特定的标签集。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM