简体   繁体   English

为Rails Geocoder Gem设置动态API密钥

[英]Setup dynamic api keys for rails geocoder gem

I'm trying to implement a general 'application settings' page for my application. 我正在尝试为我的应用程序实现常规的“应用程序设置”页面。 on this page I want my customers to be able to put their own google api key for the rails geocoder gem. 在此页面上,我希望我的客户能够为Rails geocoder gem放置自己的Google api密钥。 I have read through the documentation but could not find any way to set this api key in a dynamic way (through a form). 我已经阅读了文档,但是找不到任何以动态方式(通过表单)设置此api密钥的方法。

Is there any way to do this dynamically so the client can use his own google api key? 有没有办法动态地执行此操作,以便客户端可以使用自己的Google api密钥?

Small note, every application will only have 1 api key, but I'm trying to do this dynamically so I won't have to think about it anymore down the line. 值得注意的是,每个应用程序只有1个api密钥,但是我试图动态地做到这一点,所以我不必再考虑它了。

You could use Geocode.configure : 您可以使用Geocode.configure

Geocoder.configure(
     :timeout  => 5,
     :lookup   => :yandex,
     :api_key  => "2a9fsa983jaslfj982fjasd",
     :units    => :km
)

https://github.com/alexreisner/geocoder/blob/e45f8bd3173c28e03efbfaf03eab7c5afaf4621a/lib/geocoder/configuration.rb#L7 https://github.com/alexreisner/geocoder/blob/e45f8bd3173c28e03efbfaf03eab7c5afaf4621a/lib/geocoder/configuration.rb#L7

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM