An ActiveRecord extension that adds more kawaii validation syntax
MIT License
An ActiveRecord extension that adds more kawaii validation syntax.
The "Sexy Validation" syntax is not at all sexy.
Gemfile:
gem 'kawaii_validation'
And then execute:
$ bundle
Ruby 2.0, 2.1, 2.2, 2.3, 2.4, and 2.5 (trunk)
Rails 3.2.x, 4.0, 4.1, 4.2, 5.0, 5.1, and 5.2 (edge)
With this gem bundled, the validates
method takes a block argument, and the following two new DSLs will be enabled:
class User < ActiveRecord::Base
# validations begin
validates :name, :age, presence: true
validates :name, length: {maximum: 255}
validates :age, numericality: {greater_than: 0}
# validations end
...
end
class User < ActiveRecord::Base
validates do
presence_of :name, :age
length_of :name, maximum: 255
numericality_of :age, greater_than: 0
end
...
end
class User < ActiveRecord::Base
validates :name do
presence
length maximum: 255
end
validates :age do
presence
numericality greater_than: 0
end
...
end