सिनात्रा और ActiveRecord साथ जियोकोडर की स्थापना?

वोट
1

मैं ने MySQL डेटाबेस जो ActiveRecord और सिनात्रा का उपयोग करके पहुँचा रहा है। मैं तालिकाओं में रिकॉर्ड पर कुछ जियोलोकेशन कार्य करने के लिए कोशिश कर रहा हूँ।

हालांकि, मेरा मानना ​​है मेरी वाक्य रचना गलत है के रूप में जियोकोडर वर्ग का विस्तार करता है मेरी CRUD अनुरोध विफल:

myapp.rb

require 'rubygems'
require 'sinatra'
require 'active_record'
require 'table_print'
require 'json'

ActiveRecord::Base.establish_connection(
  :adapter  => mysql2,
  :host     => localhost,
  :username => root,
  :database => orbital
)

class Post < ActiveRecord::Base
  extend Geocoder::Model::ActiveRecord

 # attr_accessor :latitude, :longitude
end

class Comment < ActiveRecord::Base
  #extend Geocoder::Model::ActiveRecord
end

class MyApp < Sinatra::Application
  #extend Geocoder::Model::ActiveRecord
end

post '/post' do
  @user = params[:user]
  @content = params[:content]
  @latitude = params[:latitude]
  @longitude = params[:longitude]
  @timestamp = params[:timestamp]
  record = Post.create(user: @user, content: @content, longitude: @longitude, latitude: @latitude, timestamp: @timestamp)
  record.save
end

क्वेरी मैं प्रदर्शन करने के लिए कोशिश कर रहा हूँ है: Post.near([@lat, @long], @dist, units: :km).offset(10 * @var.to_i).first(10)

इस stackoverflow धागा यहाँ भी पता चलता है कि मैं सेटअप करने के लिए इस तरह के रूप में अतिरिक्त तर्कों की जरूरत है attr_accessors। मैं फिर से लिखने के ऊपर तो मैं जियोकोडर के उपयोग कर सकते हैं स्थापित करने के बारे में कैसे जाते हो nearविधि?

25/07/2018 को 13:24
का स्रोत उपयोगकर्ता
अन्य भाषाओं में...                            


1 जवाब

वोट
1

मैं जोड़कर ऊपर तय:

require 'geocoder'

तथा

reverse_geocoded_by :latitude, :longitude
25/07/2018 को 18:32
का स्रोत उपयोगकर्ता

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more