motion/validatable.rb
def validate_for(field, value)
      @messages = []
      key = field.to_sym
      result = true
      each_validation_for(key) do |validation|
        validation.each_pair do |validation_type, setting|
          method = validation_method(validation_type)
          if self.respond_to? method
            value.strip! if value.is_a?(String)
            result &&= self.send(method, field, value, setting)
          end
        end
      end
      result
    end
def validate_for(field, value)
      @messages = []
      key = field.to_sym
      result = true
      each_validation_for(key) do |validation|
        validation.each_pair do |validation_type, setting|
          method = validation_method(validation_type)
          if self.respond_to? method
            value.strip! if value.is_a?(String)
            result &&= self.send(method, field, value, setting)
          end
        end
      end
      result
    end
def validate_for ( field , value ) @messages = [ ] key = field . to_sym result = true each_validation_for ( key ) do | validation | validation . each_pair do | validation_type , setting | method = validation_method ( validation_type ) if self . respond_to? method value . strip! if value . is_a? ( String ) result &&= self . send ( method , field , value , setting ) end end end result end
Validates an arbitrary string against a specific field's validators.
 Useful before setting the value of a model's field. I.e., you get data
 from a form, do a <tt>validate_for(:my_field, that_data)</tt> and
 if it succeeds, you do <tt>obj.my_field = that_data</tt>.
Validates an arbitrary string against a specific field s validators . Useful before setting the value of a model s field . I . e . you get data from a form do a <tt > validate_for ( : my_field that_data ) < / tt > and if it succeeds you do <tt > obj . my_field = that_data< / tt > .