Search code examples
ruby-on-railsrails-geocoder

Geocoder and rails - wrong number of arguments (3 for 1)


I read all posts but don't find solution. I make a .near request with geocoder, and It work for one controller but doesn't work for another one with this error : Wrong number of arguments (3 for 1).

Here is the two same lines :

This one doesn't work in my school_controller.rb

@schools_premium = School.where(:subscription.exists => true)

@schools_aside = @schools_premium.near([params[:latitude], params[:longitude]], radius, units: :km).limit(3)

I try too with : @school.coordinates.reverse instead of params[:latitude] ..

But this one does (in home_controller.rb) :

@schools = School.near([params[:latitude], params[:longitude]], radius, units: :km).limit(30)

I have the geocoded_by and reverse_geocoder on my School model.

Does someone have the same issue ?


Solution

  • You can achieve by this way also:

    @schools = School.near([params[:latitude], params[:longitude]], radius, units: :km).limit(30)
    @schools_aside =  @schools.premium_school
    

    School.rb (model)

    scope :premium_school, -> {where("subscription = ?", true)}