Created
August 23, 2012 09:27
-
-
Save bernd/3434627 to your computer and use it in GitHub Desktop.
Validate hash via ActiveModel::Validations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'bundler/setup' | |
require 'active_model' | |
class ParamValidation | |
include ActiveModel::Validations | |
validates :page, :format => /\d+/ | |
attr_accessor :page | |
def initialize(params) | |
self.page = params[:page] | |
end | |
end | |
params = {:page => 'abc'} | |
v = ParamValidation.new(params) | |
puts v.valid?.inspect | |
puts v.errors.full_messages.inspect | |
params = {:page => 123} | |
v = ParamValidation.new(params) | |
puts v.valid?.inspect | |
puts v.errors.full_messages.inspect |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment