From 96e5e35d7c677afbb59c4b9105ae4c9db777be17 Mon Sep 17 00:00:00 2001 From: Andrew Tomaka Date: Tue, 2 Apr 2013 03:07:11 -0400 Subject: [PATCH] Validation and simple functions --- app/models/alert.rb | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/app/models/alert.rb b/app/models/alert.rb index 0d9828e..e3bc90b 100644 --- a/app/models/alert.rb +++ b/app/models/alert.rb @@ -1,3 +1,36 @@ class Alert < ActiveRecord::Base attr_accessible :alerted, :course, :department, :user_id + + validates :department, :presence => true, + :length => { + :minimum => 2, + :maximum => 4 + }, + :format => { + :with => /\A[A-Za-z]+\Z/ + } + validates :course, :presence => true, + :length => { + :minimum => 3, + :maximum => 4 + }, + :format => { + :with => /\A[0-9]+[A-Za-z]?\Z/ + } + validates :user_id, :presence => true, + :numericality => { + only_integer: true + } + + def alerted? + @alerted + end + + def class_name + @department + ' ' + @course + end + + def sections + + end end