Below is my class that I am using geocoder with. I am having trouble checking whether or not address that is put through geocoder is valid. This code works great when I am adding a company/editing a company that has addresses that when put through geocoder gives a latitude and longitude. But I need the code to work so when a user tries to put a address that does not give a latitude and longitude, on either an edit or creation of a company, that an error pops up and informs the user that the address is invalid.
Model
class Company < ActiveRecord::Base
validates :name, presence: true, length: { maximum: 30 }
validates :website, presence: true
validates :address, presence: true
validates :description, presence: true
validates :primary_field, presence: true
geocoded_by :address
before_save :geocode, if: ->(obj){ obj.address.present? and obj.address_changed? }
after_save :set_popup_value
private
...
end
View
<% provide(:title, 'Add Company') %>
<h1>Add Company</h1>
<div class="row">
<div class="span6 offset3">
<%= form_for(@company) do |f| %>
<%= render 'shared/error_messages' %>
<%= f.label :name %>
<%= f.text_field :name %>
<%= f.label :website %>
<%= f.text_field :website %>
<%= f.label :primary_field %>
<%= f.select :primary_field, @primary_field %>
<%= f.label :address %>
<%= f.text_field :address, :placeholder => '123 Test St, City State Zip'%>
<%= f.label :description %>
<%= f.text_area :description, :size => "30x5" %>
<%= f.submit "Add Company", class: "btn btn-large btn-primary" %>
<% end %>
</div>
</div>