[英]Geocoder : ArgumentError: wrong number of arguments (3 for 0..1)
I read many things about this problem but I don't find an issue for the problem. 我读到了很多有关此问题的信息,但找不到该问题的问题。 I've created a rake task that find all school in my DB, and find all premium-school.
我创建了一个瑞克任务,可以在数据库中找到所有学校,并找到所有高级学校。 I want to display, thanks to Geocoder, the 3 nearest premiums school on non-premium school.
多亏了Geocoder,我想在非优质学校中显示最近的3家优质学校。 But when I launch my task I have this error :
但是,当我启动任务时,会出现以下错误:
rake aborted!
ArgumentError: wrong number of arguments (3 for 0..1)
/Users/marchardantonin/.rvm/gems/ruby-2.0.0-p648/gems/origin-2.1.1/lib/origin/selectable.rb:334:in `near'
/Users/marchardantonin/Sites/Vroom2017/vroomvroom-web/lib/tasks/geocodeschool.rake:8:in `block (3 levels) in <top (required)>'
/Users/marchardantonin/.rvm/gems/ruby-2.0.0-p648/gems/mongoid-5.0.0/lib/mongoid/contextual/mongo.rb:668:in `yield_document'
Here is the code : 这是代码:
geocoderschool.rake geocoderschool.rake
namespace :geocodeschool do
desc "Show premium school near non-premium school and update them"
task :schgc => :environment do
@schools = School.all
@schools_premium = @schools.premium_school
radius = 30
@schools.each do |school|
@schools_aside = @schools_premium.near(school.coordinates.reverse, radius, units: :km).limit(3)
puts "les auto-écoles premiums : #{@shcools_aside.count}"
puts "-------"
@schools_aside.each do |sa|
puts sa.title
end
puts "-------"
end
end
end
school.rb school.rb
scope :premium_school, -> {where(:subscription.exists => true).where("subscription.current_period_end" => {'$gte' => Date.today})}
embeds_one :geocodeschool
accepts_nested_attributes_for :geocodeschool
geocodeschool.rb geocodeschool.rb
class Geocodeschool
include Mongoid::Document
embedded_in :school
field :school_premium_aside, type: Array
end
Does someone could explain me the error and help me to find an issue ? 有人可以向我解释错误并帮助我找到问题吗?
Thanks ! 谢谢 !
You should probably take a look at the official documentations for that gem. 您可能应该看看该宝石的官方文档 。 It only accepts a hash as arguments, such as:
它仅接受哈希作为参数,例如:
@schools_premium.near(location: [ 23.1, 12.1 ])
Having a look at the Mongoid code , it seems like you should be using geo_near
as such: 看一下Mongoid代码 ,看来您应该这样使用
geo_near
:
@schools_premium.geo_near(school.coordinates.reverse).max_distance(0.5)
Geocode's near
method should be called on a model, sending the coordinates. Geocode的
near
方法应在模型上调用,并发送坐标。
So, call it on PremiumSchool
model,and send the coordinates in @schools_premium 因此,在
PremiumSchool
模型上调用它,然后在@schools_premium中发送坐标
@schools_aside = School.near(@schools_premium.coordinates.reverse, radius, units: :km).limit(3)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.