仅允许从用户输入显示链接(Only allow links to display from user input)

编程入门 行业动态 更新时间:2024-10-06 23:18:02
仅允许从用户输入显示链接(Only allow links to display from user input)

My Rails应用程序允许用户发布使用simple_format显示的注释。 目前所有的html都已转义,但我希望用户能够在评论中发布链接。 看看这里讨论的rails_autolink gem我应该能够做到这一点,但我不知道这是否是最好/最安全的方法。

宝马说,auto_link已从rails中删除

这是从rails中提取auto_link方法。 在版本Rails 3.1中从Rails中删除了auto_link方法。 这个宝石旨在填补人们迁移的空白。

我应该如何仅允许在我的评论中显示链接?

My Rails app allows users to post comments which are displayed with simple_format. Currently all html is escaped but I'd like for users to be able to post links in their comments. Looking at the rails_autolink gem discussed here I should be able to do this but I don't know if this is the best/safest method.

auto_link was removed from rails and the gem says

This is an extraction of the auto_link method from rails. The auto_link method was removed from Rails in version Rails 3.1. This gem is meant to bridge the gap for people migrating.

How should I allow only links to be shown in my comments?

最满意答案

使用Sanitize 。

标签和属性(只允许提到的标签和属性,没有别的)。

<%= sanitize @article.body, tags: %w(a) %>

这是文档 。

Use Sanitize.

Tags and attributes (only the mentioned tags and attributes are allowed, nothing else).

<%= sanitize @article.body, tags: %w(a) %>

Here is the documentation.

更多推荐

gem,Rails,auto_link,电脑培训,计算机培训,IT培训"/> <meta name="descripti

本文发布于:2023-07-09 10:28:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1085628.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:链接   用户   links   input   user

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!