Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use within_polygon #57

Open
utkarshdalal opened this issue Mar 22, 2017 · 2 comments
Open

Cannot use within_polygon #57

utkarshdalal opened this issue Mar 22, 2017 · 2 comments
Labels

Comments

@utkarshdalal
Copy link

Hi, I'm not sure what I am doing wrong, but I am not able to use the within_polygon method.
I have a class, Complaint, which is set up like so:

class Complaint
  include Mongoid::Document
  include Mongoid::Geospatial
  include Mongoid::Timestamps::Short
  field :title
  field :description
  field :location, type: Point
  field :images, type: Array
  field :resolved, type: Boolean, default: false
  field :needs_moderation, type: Boolean, default: false
  belongs_to :complaint_type
  belongs_to :user
  has_many :comments
  has_many :likes, as: :feedbackable
  has_many :dislikes, as: :feedbackable
  has_many :moderation_requests

  validates_presence_of :title, :description

  attr_accessor :distance

  spatial_index :location, {min: -200, max: 200}

  spatial_scope :location

  scope :created_after, -> (datetime) {where(:c_at.gte => datetime)}
  scope :created_before, -> (datetime) {where(:c_at.lte => datetime)}
  scope :created_between, -> (start_time, end_time) {created_after(start_time).created_before(end_time)}

When I do Complaint.within_polygon(location: [[[1, 0], [1, 1], [0, 3]]]), I get

NoMethodError: undefined method `within_polygon' for Complaint:Class
Did you mean?  with_options
	from (irb):3
	from /Users/utkarshdalal/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/commands/console.rb:65:in `start'
	from /Users/utkarshdalal/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/commands/console_helper.rb:9:in `start'
	from /Users/utkarshdalal/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:78:in `console'
	from /Users/utkarshdalal/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
	from /Users/utkarshdalal/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/commands.rb:18:in `<top (required)>'
	from bin/rails:4:in `require'
	from bin/rails:4:in `<main>'

What am I doing wrong?

@Youngv
Copy link

Youngv commented Apr 19, 2017

@utkarshdalal
It seems mongoid have some changes of the within_polygon syntax
mongoid spec test

class Holiday
  include Mongoid::Document
  include Mongoid::Geospatial

  field :location, type: Point
end

Holiday.create!(location: [1,1])
=> #<Holiday _id: 58f722371064f877a5d1c021, location: [1.0, 1.0]>
Holiday.geo_spacial(:location.within_polygon => [[[0, 0], [0,2], [2, 2], [2, 0], [0, 0]]]).first
=> #<Holiday _id: 58f721771064f877a5d1c020, location: [1.0, 1.0]>

@dblock dblock added the bug? label Nov 9, 2018
@dblock
Copy link
Collaborator

dblock commented Nov 9, 2018

Someone care to resurrect and figure this one out?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants