Trimmable gem removes leading and trailing white spaces from the AR attribute values.
Ruby
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
test
.gitignore
README.rdoc
Rakefile
init.rb

README.rdoc

Trimmable

Trimmable lib removes leading and trailing white spaces from the AR attribute values.

Installing

Trimmable gem

sudo gem install trimmable

Trimmable plugin

Run the following command in your Rails.root:

Rails 2.x
./script/plugin install git@github.com:viola/trimmable.git

Rails 3.x
./script/rails plugin install git@github.com:viola/trimmable.git

Usage

Model

class Post < ActiveRecord::Base
  validates_presence_of :title
  trimmable_attributes :title, :comments
end

Log output:

Started POST "/posts" for 127.0.0.1 at Sun Oct 31 20:30:59 -0400 2010
Processing by PostsController#create as HTML
Parameters: {"commit"=>"Create Post", "post"=>{"comments"=>"    new comment goes here      ", "title"=>"New title    "}, "authenticity_token"=>"Hjd4K8op5TAY7rL4k176tVehIr6eHzuR0vtNIRMlfRU=", "utf8"=>"✓"}
SQL (17.3ms)  INSERT INTO "posts" ("comments", "created_at", "title", "updated_at") VALUES ('new comment goes here', '2010-11-01 00:30:59.163811', 'New title', '2010-11-01 00:30:59.163811')
Redirected to http://localhost:3000/posts/12
Completed 302 Found in 40ms