我正在尝试让地理编码器 gem 处理已使用 has_many 关系过滤的对象
像这样
user.rb
has_one :profile
has_many :roles
name:string
profile.rb
belongs_to :user
latitude,latitude:float, address:string, city:string
role.rb
belongs_to :user
name:string
我遇到的问题是我需要过滤角色说 id => 3
所以我们有
@limitrole = User.includes(:profile, :roles).where('roles.id' => 3)
这将返回一个角色有限的对象,现在获取包含地理编码内容的配置文件
@profiles = @limitrole.collect { |user| user.profile }
这将返回一个仅限于用户角色的地址对象
但这行不通
@findlocations = @profiles.near('city, country', 20) (city and country being arbitrary values)
然而这会奏效
@findlocations = Profile.near('city, country', 20)
@profiles 应该与 Profile(两个对象)相同,只是 @profiles 已被过滤。
我怎样才能让它工作?