희망 사항을 말하면 간단합니다. 그러나 나는 지금 2 시간 동안 사냥했고 이것이 일하는 것을 얻는 것처럼 보일 수 없다. 다중 주소를 가진 사용자가 있는데, 지오 코드 보석을 사용하여 우편 사용자 검색을 표시하려고 할 때 내 코드는 지오 코더 가로장에있는 것과 매우 유사합니다.Rails 모델 연합 문제
여기 내 컨트롤러 시도 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
내 모델입니다) ... 이야기 해봐 비트는 작동하지만 그것조차 그 부분에 도착하지
둘러보기에 감사드립니다.
거의 완벽했습니다. .blank를 전환해야 했습니까? .nil? – Robert
페이지 매김을 할 수없는 배열을 되 찾을 수 있습니다. – Will