Plugins - acts_as_fixed_case
Add to favoritesacts_as_fixed_case is a plugin derived from ForceUppercase. It provides the capabilities to automagically convert on before_save filter all ActiveRecord column objects of type :string or :text to their uppercase/lowercase (upcase/downcase) version, as long as they have content (nil values will remain nil).
The determination is made by querying all the columns of the AR model’s class for their type. Note that SQLLite returns type :string for SQL columns of type CHAR, VARCHAR, and TEXT.
Installation
To install the acts_as_fixed_case plugin into a current Rails application, run the script/plugin script from the root of our application passing it the URL of svn://www.microconsulting.it/acts_as_fixed_case/trunk
For example:
script/plugin install svn://www.microconsulting.it/acts_as_fixed_case/trunk
Once installed you will need to restart your webserver for the plugin to be loaded into the Rails environment.
Syntax
The syntax is easy. Simply add a class method to your ActiveRecord class definition as follows:
acts_as_fixed_case optional_arguments
where optional_arguments is one or more of the following options, separated by commas (,):
:case => upcase/downcase – default upcase
:include_text => true|false – Indicates whether or not to convert to uppercase columns of type TEXT (note SQLLite limitation described above)
:only => column_definition – Indicates that only the specified columns should be converted to uppercase
:except => column_definition – Indicates that all :string columns EXCEPT for the ones included in this option should be converted to uppercase (this will not convert columns of type TEXT unless the :include_text option is included)
type and class are columns automatically excluded.
where column_definition is a column name or an array of column names
Usage
To convert all columns of type string to uppercase
class Person < ActiveRecord::Base
acts_as_fixed_case :case => “upcase”
end
To convert column name of type string to downcase
class Person < ActiveRecord::Base
acts_as_fixed_case :case => “downcase”, :only => “name”
end
To convert all but certain columns (not including TEXT column types)
class Person < ActiveRecord::Base
acts_as_fixed_case :except => [ :title, :suffix ]
end
Special Thanks to ForceUppercase developer
