【问题标题】:restrict users from using certain tags on redcloth / textile in rails限制用户在轨道中的红布/纺织品上使用某些标签
【发布时间】:2011-01-24 16:20:15
【问题描述】:

嘿,我正在尝试找到一种方法来限制用户在表单字段中使用某些标签,例如 h1.h2.。就像我不希望他们能够炸毁表单域和垃圾邮件。

有没有办法做到这一点,还是我必须在 gem 库中更改它?

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3 textile redcloth


    【解决方案1】:

    查看这篇关于如何允许某些标签的帖子:http://jeff.jones.be/technology/articles/textile-filtering-with-redcloth/

    config/initializers/redcloth_extension.rb

    module RedCloth::Formatters::HTML
      include RedCloth::Formatters::Base
    
      def after_transform(text)
        text.chomp!
        clean_html(text, ALLOWED_TAGS)
      end
    
      ALLOWED_TAGS = {
        'a' => ['href', 'title'],
        'br' => [],
        'i' => nil
      }
    end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多