简体   繁体   English

Ruby on Rails 4上的gem'timezone'

[英]gem 'timezone' on Ruby on Rails 4

I have made an account on GeoNames enabled free webservrices to use gem 'timezone' (about a day ago). 我已经在启用了GeoNames的免费网络服务上创建了一个帐户,以使用gem'timezone'(大约一天前)。 When I go to http://www.geonames.org/enablefreewebservice it says 当我转到http://www.geonames.org/enablefreewebservice它说

 The account my_user_name has been successfully enabled to use the free webservices.

When I put the following in the address bar and click enter it works, too 当我在地址栏中输入以下内容并单击Enter时,它也起作用

http://api.geonames.org/findNearbyPostalCodes?lat=47&lng=9&username=my_user_name

However when I run the following in my Rail4 application console 但是,当我在Rail4应用程序控制台中运行以下命令时

Timezone::Configure.begin do |c|
  c.username = 'xxxx'
end
timezone = Timezone::Zone.new :latlon => [-34.92771808058, 138.477041423321]

I get the error message: 我收到错误消息:

 Timezone::Error::NilZone: No zone was found. Please specify a zone.

This is my first time using GeoNames so I'm not over the limit. 这是我第一次使用GeoNames,所以我没有超出限制。 How may I go about fixing this? 我该如何解决这个问题? One thing I noticed, require 'timezone' returns false in console. 我注意到的一件事, require 'timezone'在控制台中返回false。

Thanks. 谢谢。

I suspect your username config is probably undefined. 我怀疑您的用户名配置可能未定义。 Open the console up and check 打开控制台并检查

Timezone::Configure.username

If it's nil , you've found your problem! 如果是nil ,那么您已经找到问题了!

Try placing your config code inside an initializer, instead of application.rb . 尝试将配置代码而不是application.rb放置在初始化application.rb Try creating the file config/initializers/timezone.rb and place the code there. 尝试创建文件config/initializers/timezone.rb并将代码放在此处。

Timezone::Configure.begin do |c|
  c.username = 'xxxx'
end

Fire up the console after that and check the username again. 之后启动控制台,然后再次检查用户名。 If it's now defined your request should now work! 如果现在已定义,您的请求现在应该可以正常工作!

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

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