PreventBlankificationValidator

Build Status Code Coverage Code Climate Gem Version Dependency Status

Rails 3 Validator, that prevents attributes from being changed to a blank value once they're present.

Installation

Add this line to your application's Gemfile:

gem 'prevent_blankification_validator'

And then execute:

$ bundle

Or install it yourself as:

$ gem install prevent_blankification_validator

Usage

class MyModel
  validates :value, prevent_blankification: true
end

model.value = 'present'
model.save             # => true

model.value = ''
model.valid?           # => false

model.value = "\r    \n  "
model.valid?           # => false

model.value = nil
model.valid?           # => false

model.value = 'present as well'
model.valid?           # => true

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request