def validates_attached_extension(name, options = {})

      message = options[:message] || "extension is invalid"

      options[:in] ||= [options[:is]] if options[:is]

      range = options[:in].map { |element| ".#{element}" }

      validates_inclusion_of :"#{name}_extension", in: range, message: message,
        if: options[:if], unless: options[:unless]
    end
def validates_attached_extension(name, options = {})

      message = options[:message] || "extension is invalid"

      options[:in] ||= [options[:is]] if options[:is]

      range = options[:in].map { |element| ".#{element}" }

      validates_inclusion_of :"#{name}_extension", in: range, message: message,
        if: options[:if], unless: options[:unless]
    end
Validates an attached extension in a specified set.

 Options:

 * :in - allowed values for attached

 Usage:

   validates_attached_extension :avatar, is: 'png'
   validates_attached_extension :avatar, in: %w(png jpg)
   validates_attached_extension :avatar, in: [:png, :jpg]
   validates_attached_extension :avatar, in: %w(png jpg), message: "extension must be :in"
   validates_attached_extension :avatar, in: %w(png jpg), message: "extension must be :in"