Skip to content

Instantly share code, notes, and snippets.

@pencilcheck
Created November 16, 2013 01:27
Show Gist options
  • Save pencilcheck/7494668 to your computer and use it in GitHub Desktop.
Save pencilcheck/7494668 to your computer and use it in GitHub Desktop.
model
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