我读到了很多有关此问题的信息,但找不到该问题的问题。我创建了一个瑞克任务,该任务在数据库中查找所有学校,并查找所有高级学校。多亏了Geocoder,我想在非优质学校中显示最近的3家优质学校。但是,当我启动任务时,会出现以下错误:
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'
这是代码:
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
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
class Geocodeschool
include Mongoid::Document
embedded_in :school
field :school_premium_aside, type: Array
end
有人可以向我解释错误并帮助我找到问题吗?
谢谢 !
Geocode的near
方法应在模型上调用,并发送坐标。
因此,在PremiumSchool
模型上调用它,并在@schools_premium中发送坐标
@schools_aside = School.near(@schools_premium.coordinates.reverse, radius, units: :km).limit(3)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句