Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I see following problems in your code:</p> <p>1) Duplicate presence checks </p> <p>2) Auto and manual geo coding at the same time.</p> <p>Here is a version of your code that might work:</p> <pre><code>class Entry &lt; ActiveRecord::Base acts_as_mappable acts_as_taggable_on :tags validates_presence_of :name, :tag_list validate :required_info before_save :geocode_paddress private def required_info if( phone.empty? and phone2.empty? and tollfreephone.empty? and mobile.empty? and fax.empty? and email.empty? and website.empty? ) errors.add_to_base "Please have at least one form of contact information." end end def geocode_paddress # if paddress is nil or empty set the old values to nil and return ((self.lat = self.lng = nil); return true) if paddress.empty? g=Geokit::Geocoders::MultiGeocoder.geocode(paddress) (errors.add(:paddress,"Could not Geocode address"); return false) unless g.success self.lat, self.lng = g.lat, g.lng end end </code></pre> <p><strong>Edit</strong></p> <p>The <code>required_info</code> validation fails as the input data submitted by the form contains empty strings for missing fields rather than null values. Hence the <code>phone or phone2 etc.</code> check always returned true. I have changed the validation code to address this edge case. I am quite sure it will work now.</p> <p><strong>PS:</strong> This is a typical scenario where you should be using a debugger. Download and play with any free IDE like Aptana Radrails OR Netbeans. Once you are familiar with the tool you will be able to easily debug such issues.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload