Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 661051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:13:32+00:00 2026-05-13T23:13:32+00:00

I have a Rails application that lists information about local services. My objectives for

  • 0

I have a Rails application that lists information about local services. My objectives for this model are as follows: 1. Require the name and tag_list fields. 2. Require one or more of the tollfreephone, phone, phone2, mobile, fax, email or website fields. 3. If the paddress field has a value, then encode it with the Geokit plugin. Here is my entry.rb model:

class Entry < ActiveRecord::Base

  validates_presence_of :name, :tag_list
  validates_presence_of :tollfreephone or :phone or :phone2 or :mobile or :fax or :email or :website
  acts_as_taggable_on :tags
  acts_as_mappable :auto_geocode=>{:field=>:paddress, :error_message=>'Could not geocode physical address'}

  before_save :geocode_paddress
  validate :required_info

  def required_info
    unless phone or phone2 or tollfreephone or mobile or fax or email or website
      errors.add_to_base "Please have at least one form of contact information."
    end
  end

  private
  def geocode_paddress
    #if paddress_changed?
    geo=Geokit::Geocoders::MultiGeocoder.geocode (paddress)
    errors.add(:paddress, "Could not Geocode address") if !
geo.success
    self.lat, self.lng = geo.lat,geo.lng if geo.success
    #end 
  end
end

Requiring name and tag_list work, but requiring one (or more) of the tollfreephone, phone, phone2, mobile, fax, email or website fields does not.

As for encoding with Geokit, in order to save a record with the model I have to enter an address. Which is not the behavior I want. I would like it to not require the paddress field, but if the paddress field does have a value, it should encode the geocode. As it stands, it always tries to geocode the incoming entry. The commented out “if paddress_changed?” was not working and I could not find something like “if paddress_exists?” that would work.

Help with any of these issues would be greatly appreciated. I posted three questions pertaining to my model because I’m not sure if they are preventing each other from working. Thank you for reading my questions.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T23:13:32+00:00Added an answer on May 13, 2026 at 11:13 pm

    I see following problems in your code:

    1) Duplicate presence checks

    2) Auto and manual geo coding at the same time.

    Here is a version of your code that might work:

    class Entry < 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
    

    Edit

    The required_info validation fails as the input data submitted by the form contains empty strings for missing fields rather than null values. Hence the phone or phone2 etc. check always returned true. I have changed the validation code to address this edge case. I am quite sure it will work now.

    PS:
    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a Rails 3 application. I have images that can be tied to
I have a Rails application that in the erb code, I use a select
I have a Rails application that unfortunately after a request to a controller, has
We have a rails application in subversion that we deploy with Capistrano but have
Do the major web application frameworks (Rails, Django, etc) have libraries that provide functionality
I have created a table in my Ruby on Rails application that I am
I have a Ruby on Rails application that allows for users to create a
I have a rails application where each user has a separate database. (taking Joel
I have a rails application which is still showing the cachebusting numeric string at
I have a rails application running on a Linux server. I would like to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.