Repository URL to install this package:
|
Version:
0.4.2 ▾
|
module Neoteric
module Event
def self.included(base)
base.table_name = 'events'
base.attr_accessible :title, :starts, :ends, :location, :venue_url, :description
base.extend ::FriendlyId
base.friendly_id :title, :use => :slugged
base.send(:include, ::Neoteric::Archiver)
base.archive_fields :starts => :starts,
:ends => :ends
base.send(:include, ::Neoteric::Navigator)
base.navigate :field => :starts,
:order => 'starts DESC'
base.validates :venue_url, :url => true
base.validate :ends_after_start
base.scope :upcoming, base.where('starts > ?', Time.now)
end
def ends_after_start
return true if ends.blank? || starts.blank?
unless ends > starts
errors.add(:base, "Event should end later than it starts")
end
end
end
end
class UrlValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
return true if value.blank?
unless /^https?:\/\/\S+\.\w{2,}\S+?$/ =~ value
record.errors.add(attribute, 'is invalid')
end
end
end