app/controllers/findfriend_controller.rb
# Return true if the browse form input is valid, false otherwise.
Return true if the browse form input is valid, false otherwise.
Return true if the browse form input is valid false otherwise .
def valid_input?
    @contact = Contact.new
    zip_code = params[:zipcode]
    @contact.zipcode = zip_code
    miles = params[:miles]
    if miles and zip_code.blank?
      @contact.errors.add(:zipcode, "不能保留空白")
    end
    location = GeoDatum.find_by_zipcode(zip_code)
    if @contact.valid? and not zip_code.blank? and location.nil?
      @contact.errors.add(:zipcode, "找不到這個郵遞區號")
    end
    if !zip_code.blank? and miles.blank?
      @contact.errors.add(:miles, "請輸入要搜尋的範圍")
    elsif !miles.blank? and not miles.valid_float?
      @contact.errors.add(:miles, "請輸入合法的搜尋範圍")
    end
    @contact.errors.empty?
  end
def valid_input? @contact = Contact . new zip_code = params [ :zipcode ] @contact . zipcode = zip_code miles = params [ :miles ] if miles and zip_code . blank? @contact . errors . add ( :zipcode , "不能保留空白") end location = GeoDatum . find_by_zipcode ( zip_code ) if @contact . valid? and not zip_code . blank? and location . nil? @contact . errors . add ( :zipcode , "找不到這個郵遞區號") end if ! zip_code . blank? and miles . blank? @contact . errors . add ( :miles , "請輸入要搜尋的範圍") elsif ! miles . blank? and not miles . valid_float? @contact . errors . add ( :miles , "請輸入合法的搜尋範圍") end @contact . errors . empty? end
Return true if the browse form input is valid, false otherwise.
Return true if the browse form input is valid false otherwise .
# The zip code is necessary if miles are provided. # There are a good number of zip codes for which we have no information. # The number of miles should convert to a valid float. # The input is valid iff the errors object is empty.