Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gmaps4rails validates before validates presence set to true

I encountered the following error when I submit an empty address field.

Gmaps4rails::GeocodeInvalidQuery in LocationsController#create You must provide an address

My Model

class Location < ActiveRecord::Base
  validates :address, :presence => true

  acts_as_gmappable
  def gmaps4rails_address
    address
  end

  def gmaps4rails_infowindow
    "<h4>#{name}</h4>" << "<h4>#{address}</h4>"
  end
end

The question why it never validates the address field presence or not and directly throw error?

like image 477
Edmund Ng Avatar asked Oct 11 '22 22:10

Edmund Ng


1 Answers

Fixed in 0.8.7 it will now normally add error to the address field.

Gmaps4rails already checks whether or not the address is empty or nil. It's part of the options described here.

You can, for instance, set your own validation message this way:

acts_as_gmappable :msg => "Errrrrrrror"
like image 77
apneadiving Avatar answered Oct 14 '22 01:10

apneadiving