Skip to content

Cannot use within_polygon #57

@utkarshdalal

Description

@utkarshdalal

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions