Files
ch420/app/models/supporter.rb
T

32 lines
978 B
Ruby
Raw Normal View History

2015-10-02 21:19:00 +02:00
class Supporter
include Mongoid::Document
2015-10-05 14:48:54 +02:00
include Mongoid::Timestamps
2015-10-06 13:07:01 +02:00
include Geocoder::Model::Mongoid
geocoded_by :address
after_validation :geocode # auto-fetch coordinates
2015-10-02 21:34:31 +02:00
2015-10-03 06:38:11 +02:00
field :first_name, type: String
field :last_name, type: String
field :street, type: String
field :zip, type: Integer
2015-10-05 14:12:05 +02:00
field :city, type: String
2015-10-03 06:38:11 +02:00
field :email, type: String
field :support, type: String # Indicates the type of support
2015-10-02 21:34:31 +02:00
field :age_category, type: String
2015-10-06 13:07:01 +02:00
field :coordinates, type: Array
2015-10-02 21:34:31 +02:00
2015-10-06 09:30:35 +02:00
validates :first_name, presence: true
validates :last_name, presence: true
validates :street, presence: true
validates :zip, presence: true
validates :city, presence: true
2015-10-03 06:38:11 +02:00
validates :email, presence: true, uniqueness: true
validates :support, presence: true
validates :age_category, presence: true
2015-10-06 13:07:01 +02:00
def address
"#{street}, #{zip}, #{city}, Switzerland"
end
2015-10-02 21:19:00 +02:00
end