Trimmable lib removes leading and trailing white spaces from the AR attribute values.
sudo gem install trimmable
Run the following command in your Rails.root:
Rails 2.x ./script/plugin install [email protected]:viola/trimmable.git Rails 3.x ./script/rails plugin install [email protected]:viola/trimmable.git
class Post < ActiveRecord::Base validates_presence_of :title trimmable_attributes :title, :comments end
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