住所投稿すればaddressから緯度経度、セルフで所得してgoogle mapにピンを立てれるようにしようとしています。
その際に住所入力して送信した際に
NameError in TweetsController#create
constant Tweet::HTTP
のエラーが発生する。
res = HTTP.get(uri).to_sのコードが指摘されています。
DBに直接、住所緯度経度、入力すれば問題なく表示されます。
原因は何でしょうか?
ご教授願いします。
ファイル名tweet.rb geocoded_by :address after_validation :geocode def geocode uri = URI.escape("https://maps.googleapis.com/maps/api/geocode/json?address="+self.address.gsub(" ", "")+"&key=#{Rails.application.secrets.google_map_api}") res = HTTP.get(uri).to_s response = JSON.parse(res) self.latitude = response["results"][0]["geometry"]["location"]["lat"] self.longitude = response["results"][0]["geometry"]["location"]["lng"] end
ファイル名tweets_controller.rb def create Tweet.create(tweet_params) end private def tweet_params params.require(:tweet).permit(:image, :text,:address, :latitude, :longitude).merge(user_id: current_user.id) end
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/02/15 07:29
2020/02/15 07:42
2020/02/15 07:42
2020/02/15 07:46