Module: Rubymisc::ArValidates

Defined in:
lib/rubymisc/ext/active_record.rb

Instance Method Summary collapse

Instance Method Details

#validates_email(attribute = :email) ⇒ Object



12
13
14
15
16
# File 'lib/rubymisc/ext/active_record.rb', line 12

def validates_email(attribute = :email)
  validates_presence_of attribute
  validates_length_of attribute, :minimum => 5
  validates_format_of attribute, :with => Regex.email, :message => %/isn't a valid email./
end

#validates_image_url(attribute = :image_url) ⇒ Object



18
19
20
21
22
23
# File 'lib/rubymisc/ext/active_record.rb', line 18

def validates_image_url(attribute = :image_url)
  validates attribute, allow_blank: true, format: {
    with: %r{\.(gif|jpg|png)$}i,
    message: 'must be a URL for GIF, JPG or PNG image.'
  }
end

#validates_url(attribute = :url) ⇒ Object



6
7
8
9
10
# File 'lib/rubymisc/ext/active_record.rb', line 6

def validates_url(attribute = :url)
  validates_presence_of attribute
  validates_length_of attribute, :minimum => 12
  validates_format_of attribute, :with => Regex.url, :message => %/isn't a valid URL./
end