Simple Ruby Login Verification Library

I searched everywhere for a simple input validation library for Ruby. Everything seems to point to ActiveRecord (or similar). I do not use Rails, I use Sinatra without ORM. What is the best approach to validate user input (without binding directly to the model layer)? Simple things like string length, numeric, etc. Preferably with a good mechanism for reporting error messages.

+11
input ruby validation sinatra
Aug 05 '10 at 15:44
source share
2 answers

You can use ActiveModel :: Validations, from Rails 3 RC:

require 'active_model' # this appears to be a bug in ActiveModel - it uses this, but does not require it require 'active_support/core_ext/hash' class Model include ActiveModel::Validations attr_accessor :name validates_presence_of :name end m = model.new puts m.valid? # false m.name = "John Doe" puts m.valid? # true 
+9
Aug 05 '10 at 18:51
source share

Well, I wrote one of my http://rubygems.org/gems/validates_simple , hope this helps. It checks hashes, which are the most common input structure in web applications.

0
Dec 31 '14 at 20:17
source share



All Articles