Skip to content

Model Customization

apneadiving edited this page Feb 16, 2011 · 16 revisions

Declaration in model

Basic

The easiest way to declare gmaps4rails in your model is:

acts_as_gmappable

The following default config will be assumed:

  • :process_geocoding => true : the geocode will be performed each time the model through a validate method

  • :validation => true : if the position of the address provided isn't found by google, an error will be displayed

  • :lat_column => "gmaps4rails_latitude", :lng_column => "gmaps4rails_longitude" : latitude and longitude will be saved in the tables gmaps4rails_latitude and gmaps4rails_longitude

  • :check_process => true, :checker => "gmaps : the status of the geocode, will be saved in a boolean called gmaps

Custom

All or part of these default behaviours can be customized with the following arguments:

  • :lat_column : string

  • :lng_column : string

  • :process_geocoding : true/false

These are only used if process_geocoding is true:

  • :check_process : true/false

  • :checker : string (only if check_process is true)

  • :validation : true/false

  • :msg : string, to customize the error message in validation (if activated)

Example

You could do the following:

acts_as_gmappable :process_geocoding => false, :lat_column` => "latitude", :lng_column => "longitude"