gmaps4rails validates before validates presence set to true
I encountered the following error when I submit an empty address field.
G开发者_Go百科maps4rails::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?
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"
精彩评论