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 7054849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:40:37+00:00 2026-05-28T03:40:37+00:00

Hopefully this will be simple. But I’ve hunted for a couple hours now and

  • 0

Hopefully this will be simple. But I’ve hunted for a couple hours now and can’t seem to get this to work. I have users who have multiple addresses, I’m trying to use Geocoder gem to display these users by a zip code search, my code is very similar to what is in the Geocoder Railscast.

Here’s my controller attempt 1 and returns “undefined method `Addresses'”

def index
  if params[:search].present?
    @profiles = Profile.Addresses.near(params[:search], 25, :order => :distance)
    @title = "Therapists Near " + :search
  else
  @profiles = Profile.all
  @title = "Everyone"
  end
end

This is attempt number 2, this returns “uninitialized constant ProfilesController::Addresses” (I don’t know if the Profile.where bit will work, but its not even getting to that part…)

class ProfilesController < ApplicationController

  def index
    if params[:search].present?
      addresses = Addresses.near(params[:search], 25, :order => :distance)
      @profiles = Profile.where(:id => addresses.id)
      @title = "Therapists Near " + :search
    else
    @profiles = Profile.all
    @title = "Everyone"
    end
  end

Here’s my models:

class Profile < ActiveRecord::Base
  has_many :addresses, :dependent => :destroy
  accepts_nested_attributes_for :addresses, :reject_if => lambda { |a| a[:street].blank? }, :allow_destroy => true

class Address < ActiveRecord::Base
  belongs_to :profile
  geocoded_by :street
  after_validation :geocode, :if => :street_changed?

Thanks a lot for taking a look!

  • 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-28T03:40:38+00:00Added an answer on May 28, 2026 at 3:40 am

    Additional, you may change to the following to get all profiles:

    addresses = Address.near(params[:search], 25, :order => :distance)
    
    @profiles = addresses.map{ |ad| ad.profile }.uniq unless addresses.nil?
    

    If there are matched addresses, then find the profile from each address.

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

Sidebar

Related Questions

New to MVC, so hopefully this will be pretty simple. I have an HTML
This will hopefully be a simple one: I have a div I want to
Hopefully this will be a simple fix. I'm completely new to XSL but I've
Hopefully this is a simple one, but not sure if it will be as
I have just started looking at javascript so hopefully this will be something simple.
Hopefully this is a simple one, but can anyone provide some simple c# code
Hopefully this explanation will make sense, but what is the best way (if it
Hopefully this is just a stupid mistake, but I can't see it. ; OK
Hopefully something simple but have tried and tried and keep failing. I am attempting
I'm sure this is simple but my brain just isnt working today! I have

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.