Rails Geocoder - Still Learning

I am sure this is just a problem due to the fact that I do not quite understand how bits are combined in Rails ...

I watched the rails, but I had problems with its implementation in my application (it worked autonomously for me).

The error I get is

undefined method nearbys

Here is what I have: user.rb

  geocoded_by :full_address   
  after_validation :geocode

  def full_address
    [address1, address2, address3, city, country, postcode].compact.join(', ')   
  end

users_controller.rb

def index
    @title = "All users"

    if params[:search].present?
      @users = User.near(params[:search], 50, :order => :distance)
    else
      @users = User.all
    end
end

index.html.erb

<h3>Nearby locations</h3>
<ul>
<% for user in @users.nearbys(10) %>
  <li><%= link_to user.address1, user %> (<%= user.distance.round(2) %> miles)</li>
<% end %>
</ul>

_sidebar.html.erb

            <%= form_tag users_path, :method => :get do %>
                <p>
                <%= text_field_tag :search, params[:search] %>
                <%= submit_tag "Search Near", :name => nil %>
                </p>
            <% end %>

thank

If I comment on .nearbys

<% for user in @users#.nearbys(10) %>
  <li><%= link_to user.latitude, user %> (<%= user.distance.round(2) %> miles)</li>
<% end %>

Search works. Could this be a problem with installing a geocoder?

+5
source share
1 answer

nearbys - , . @users User. , , @users.

, , :

<% @users.each do |user| %>
  <% user.nearbys(10).each do |near_user| %>
    <li><%= link_to near_user.latitude, near_user %> (<%= near_user.distance.round(2) %> miles)</li>
  <% end %>
<% end %>

( , for user in @users @users.each do |user|, "Rubyish".)

+4

All Articles