0

Ruby On Rails を使用して webbapp 用の API を構築しています。API/JSON および Geokit 用に Jbuilder を使用しています。

私はこのモデルを持っています:

運動

class Campaign < ActiveRecord::Base
    belongs_to :company
    belongs_to :venue
    belongs_to :category
    has_and_belongs_to_many :venues
    has_many :cities, through: :venues
    has_many :uses
end

会社

class Company < ActiveRecord::Base
  has_many :venues
  has_many :campaigns
  validates :name, presence: true
end

会場

class Venue < ActiveRecord::Base

    acts_as_mappable :default_units => :kms,
                     :lat_column_name => :lat,
                     :lng_column_name => :lng

    belongs_to :company
    belongs_to :city
    has_and_belongs_to_many :campaigns

end

次のように、指定された緯度と経度の座標ですべてのキャンペーンを一覧表示しようとしています。

class API::CampaignsController < ApplicationController
    respond_to :json

    def index
        @campaigns = filter
        respond_with @campaigns
    end
    def filter
        if params[:city_id]
            Campaign.includes(:venues, :cities).where('cities.id' => params[:city_id])
        elsif params[:lat] && params[:lng]
            lat = params[:lat].to_f
            lng = params[:lng].to_f
            Campaign.includes(:venues, :cities).within(10, :origin => [lat, lng])
        end
    end

end

しかし、私が得るのは空のハッシュだけです:

{
campaigns: [ ]
}

私が間違っていることと、これを修正する方法について何か考えはありますか?

4

1 に答える 1