うまくいけば、これは簡単になります。しかし、私は今数時間狩りをしていて、これを機能させることができないようです。複数の住所を持つユーザーがいます。Geocodergemを使用して、これらのユーザーを郵便番号検索で表示しようとしています。私のコードは、GeocoderRailscastにあるものと非常によく似ています。
これが私のコントローラーの試み1で、「未定義のメソッド`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
これは試行番号2であり、「初期化されていない定数ProfilesController :: Addresses」を返します(Profile.whereビットが機能するかどうかはわかりませんが、その部分に到達することすらできません...)
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
これが私のモデルです:
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?
ご覧いただきありがとうございます!