googleのmap使用でapi 入手しました。
API_key直に打つとエラーなく表示できますが。
シークレットkeyとして変数に入れて表示するとエラーが出てうまく表示できません。
ご教授お願いします。
下記の表記で現在使用してます。
ここ以外のファイルにもコード書かないといけないのでしょうか?
ターミナル $ EDITOR="vi" bin/rails credentials:edit aws: access_key_id: 自分で所得したkey secret_access_key: 自分で所得したkey google_map_api: 自分で所得したkey
ファイル名post.rb geocoded_by :address after_validation :geocode private def geocode uri = URI.escape("https://maps.googleapis.com/maps/api/geocode/json?address="+self.address.gsub(" ", "")+"&key=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
あなたの回答
tips
プレビュー