开发者

Sanitizing video embedding code in Rails. What's a good solution?

开发者 https://www.devze.com 2023-01-07 02:45 出处:网络
What\'s your preferred method of sanitizing embed code entered in a form? In other words, is there an easy way of ONLY allowing users to embed video from YouTube and Vimeo for example? Do you use the

What's your preferred method of sanitizing embed code entered in a form? In other words, is there an easy way of ONLY allowing users to embed video from YouTube and Vimeo for example? Do you use the Sanitize helper? If there is a proven solution to this I'd prefer to use it rather than reinventing the wheel. Thank you for r开发者_如何学Pythoneading my question.


I would give the users custom tags for this, rather than trying to jump through the hoops required to verify embed tags.

For example:

[youtube id=kG16SqUl3bE]

Parse out the ID and generate the embed tag yourself in the view. Safe and easy, and you don't have to allow your users to enter HTML.

0

精彩评论

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