Strip Attributes plugin

Plugin details

StripAttributes is a Rails plugin that automatically strips all ActiveRecord model attributes of leading and trailing whitespace before validation. If the attribute is blank, it strips the value to +nil+.

It works by adding a before_validation hook to the record. By default, all attributes are stripped of whitespace, but :only and :except options can be used to limit which attributes are stripped. Both options accept a single attribute (:only => :field) or arrays of attributes (:except => [:field1, :field2, :field3]).

Websitehttp://stripattributes.rubyforge.org/ Repositoryhttp://stripattributes.rubyforge.org/svn/tags/strip_attributes/ Author Ryan McGeary Tags ActiveRecord LicenseMIT

Documentation

Install the plugin:
ruby script/plugin install http://stripattributes.rubyforge.org/svn/tags/strip_attributes/
  class DrunkPokerPlayer < ActiveRecord::Base
    strip_attributes!
  end

  class SoberPokerPlayer < ActiveRecord::Base
    strip_attributes! :except => :boxers
  end

  class ConservativePokerPlayer < ActiveRecord::Base
    strip_attributes! :only => [:shoe, :sock, :glove]
  end



If you want to use this outside of Rails, extend StripAttributes in your ActiveRecord model after putting strip_attributes in your $LOAD_PATH:

  require 'strip_attributes'
  class SomeModel < ActiveRecord::Base
    extend StripAttributes
    strip_attributes!
  end

Further Documentation

There is currently no advanced documentation for this plugin.

New documentation

Edit plugin | (0 older versions) | Last edited by: Guest, about 1 year ago