Created
November 16, 2013 01:27
-
-
Save pencilcheck/7494668 to your computer and use it in GitHub Desktop.
model
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Schedule | |
include Mongoid::Document | |
include Mongoid::MultiParameterAttributes # Needed for DateTime | |
include Mongoid::Search | |
include Mongoid::Timestamps | |
include Geocoder::Model::Mongoid | |
before_create :geocode # only once, when created | |
field :coordinates, type: Array | |
field :course_name, type: String, default: "" | |
field :street, type: String, default: "" | |
field :city, type: String, default: "" | |
field :state, type: String, default: "" | |
field :cube, type: String, default: "---" | |
search_in :base_rate, :course_name, :street, :city, :state, instructor: :full_name | |
geocoded_by :address | |
def address | |
[street, city, state].join(', ') | |
end | |
def address=(val) | |
aval = val.split(',') | |
if aval.length == 3 | |
self.street, self.city, self.state = aval | |
elsif aval.length == 2 | |
self.street, self.city = aval | |
self.state = 'CA' | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment