Sha256: 6d96580b5b8283feed874f5259ba3ad7bf0b3b9e9c2eb9695e89218828ba309b
Contents?: true
Size: 760 Bytes
Versions: 3
Compression:
Stored size: 760 Bytes
Contents
require 'active_model' module ActiveModel module Validations class CreditCardValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) if !value.blank? && !CreditCardValidation::Validator.new(value).valid? record.errors.add(attribute, options[:message] || "is not a valid credit card") end end end module HelperMethods # Validates whether the value of the specified attribute is a validate Credit Card # # class Order < ActiveRecord::Base # validates_credit_card :card_number # end # def validates_credit_card(*attr_names) validates_with CreditCardValidator, _merge_attributes(attr_names) end end end end
Version data entries
3 entries across 3 versions & 1 rubygems