سؤال

Hey I'm trying to find a way to restrict users from using certain tags like h1. or h2.in the form field. Like I dont want them to be able to blow up the form field and spam.

Is there way to do that or do I have to change it in the gem library?

هل كانت مفيدة؟

المحلول

Checkout this post on how to allow certain tags: 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
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top