Rails3 和自动 nofollow 链接
我有一些模型,让它成为带字段的帖子:内容。任何用户都可以使用 html 提交帖子(当然还有链接:)),我想在这些链接上设置 nofollow。有没有任何 Rails 插件可以自动执行此任务?这个插件是否能够以有条件的方式管理“nofollowing” - 例如管理员可以添加不带nofollow的链接,但其他 - 仅使用nofollow?
i have some model, let it be Post with field :content. Any user can submit post with html (with links of course:) ) and i'd like to set nofollow on those links. Is there any rails plugin to automate this task? Does this plugin have ability to manage "nofollowing" in conditional way - e.g. admin can add links without nofollow, but other - with only nofollow?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这应该可以满足您的要求: https://github.com/rgrove/sanitize/
安装插件,然后对于可以运行的文本块:
还有其他选项可用于自定义它,但 Config::BASIC 版本将检测该文本块中的所有链接并向其添加 nofollow 标记。
This should do what you're looking for: https://github.com/rgrove/sanitize/
Install the plugin, then for a block of text you can run:
There are other options that you can use to customise it, but the Config::BASIC version will detect all links in that block of text and add the nofollow tag to them.
您可以为此定义一个助手,覆盖(或者更确切地说包装)默认的 link_to
在 app/helpers/posts_helper.rb 中执行以下操作:
这样在您看来您可以执行以下操作:
这应该导致:
您应该有一个好好看看 link_to 的实际实现,让你的“nf_link_to”像你想要的那样复杂(如;传递参数,也许是一个块)。
You can define a helper for this, overriding (or rather wrapping) the default link_to
In app/helpers/posts_helper.rb do something along the lines of:
So that in your view you can do:
Which should result in:
You should have a good look at the actual implementation of link_to and make your ''nf_link_to'' as complex as (as in; passing arguments and perhaps a block) as you desire.