GeoCoder for two different models

Hi All,
In my new project i am using geocoder gem for finding the
nearest things to a location can i use it for two different models
like i have a volunteer model
and party model
when ever a party created
i should find the volunteers which are near to a party.

On Oct 13, 2011, at 3:51 AM, venkata reddy wrote:

Hi All,
In my new project i am using geocoder gem for finding the
nearest things to a location can i use it for two different models
like i have a volunteer model
and party model
when ever a party created
i should find the volunteers which are near to a party.

Can you post what you’ve tried? I was just working on this last night,
with great success, so I may be able to help you.

Walter

The two different models are Party and volunteer.
I have to find all the volunteers who are near to a party.
Here is mycode

Parties#show
def show
@party = Party.find(params[:id])
@volunteers = Volunteer.near(@party.latitude, @party.longitude,
10, :order => :distance)

end

and
show.html.erb in party views

    <% for volunteer in @volunteers %>
  • <%= link_to volunteer.first_name, volunteer %> (<%= volunteer.distance.round(2) %> miles)
  • <% end %>

But i am getting the following error

undefined method `to_coordinates’ for 17.4359:Float

Got it
it should be @volunteers = Volunteer.near([@party.latitude,
@party.longitude], 10, :order => :distance)

venkata reddy wrote in post #1026555:

Got it
it should be @volunteers = Volunteer.near([@party.latitude,
@party.longitude], 10, :order => :distance)

Thank you, venkata! Very little clear and concise documentation out
there and this kind of help is much appreciated!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs