これは簡単なことです。しかし、私は数時間前から狩りをしてきましたが、これを働かせるようには見えません。私は複数のアドレスを持つユーザーがいます。ジオコーダーの宝石を使用してこれらのユーザーを郵便番号検索で表示しようとしています。私のコードはジオコーダーのレールキャストにあるものと非常によく似ています。RailsでのModel Associationの問題
ここに私のコントローラの試み1だと「未定義のメソッド `アドレス」
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を::アドレス』のプロフィールならば(私は知りません
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?
:
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
は、ここに私のモデルです)... .whereビットは動作しますが、そのも、その部分にはなっていません
ありがとうございました!
これはほぼ完全に機能しました。 .blankを切り替える必要がありましたか? .nilに? – Robert
ページ設定できない配列を返す – Will