TZInfo::DataSourceNotFound 在 Windows 上启动 Rails v4.1.0 服务器时出错 [英] TZInfo::DataSourceNotFound error starting Rails v4.1.0 server on Windows

查看:69
本文介绍了TZInfo::DataSourceNotFound 在 Windows 上启动 Rails v4.1.0 服务器时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Ruby on Rails v4.1.0 创建了一个新应用程序.尝试在 Windows 上启动服务器或控制台时,我遇到以下错误:

I have created a new application using Ruby on Rails v4.1.0. When attempting to start a server or console on Windows, I am encountering the following error:

$ rails server
Booting WEBrick
Rails 4.1.0 application starting in development on ....

Exiting
c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/tzinfo-1.1.0/lib/tzinfo/data_source.rb:199:
in `rescue in create_default_data_source': 
No timezone data source could be found. To resolve this, either install 
TZInfo::Data (e.g. by running `gem install tzinfo-data`) or specify a zoneinfo 
directory using `TZInfo::DataSource.set(:zoneinfo, zoneinfo_path)`.
(TZInfo::DataSourceNotFound) 
from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/tzinfo-1.1.0/lib/tzinfo/data_source.rb:196:
in `create_default_data_source'

我该如何解决这个错误?

How can I resolve this error?

推荐答案

解决错误

要解决此错误,您需要确保 tzinfo-data gem 包含在您的 Gemfile 中.

To resolve this error, you'll need to make sure that the tzinfo-data gem is being included in your Gemfile.

首先,检查您的 Gemfile 以查看是否存在对 tzinfo-data 的引用.如果还没有引用,则添加以下行:

First of all, check your Gemfile to see if there is an existing reference to tzinfo-data. If there isn't already a reference, then add the following line:

gem 'tzinfo-data'

你可能会发现已经有如下一行:

You may find that there is already a line like the following:

gem 'tzinfo-data', platforms: [:mingw, :mswin]

如果您在 Windows 上使用 64 位版本的 Ruby,则将 :x64_mingw 添加到平台列表中,如下所示:

If you are using a 64-bit version of Ruby on Windows, then add :x64_mingw to the list of platforms as follows:

gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw]

或者,您可以完全删除 platforms 选项.

Alternatively, you can remove the platforms option altogether.

执行此操作后,在命令行运行 bundle update 以安装 tzinfo-data gem,然后您就可以启动 Rails 服务器或控制台.

After doing this, run bundle update at the command line to install the tzinfo-data gem and you'll then be able to start your Rails server or console.


背景

TZInfo::DataSourceNotFound 错误是由 TZInfo 引发的,TZInfo 是 Rails 的 Active Support 组件的依赖项.TZInfo 正在寻找您系统上的时区数据源,但未能找到.

The TZInfo::DataSourceNotFound error is being raised by TZInfo, a dependency of the Active Support component of Rails. TZInfo is looking for a source of time zone data on your system, but failing to find one.

在许多基于 Unix 的系统(例如 Linux)上,TZInfo 能够使用系统 zoneinfo 目录作为数据源.但是,Windows 不包含这样的目录,因此需要安装 tzinfo-data gem.tzinfo-data gem 包含相同的 zoneinfo 数据,打包为一组 Ruby 模块.

On many Unix-based systems (e.g. Linux), TZInfo is able to use the system zoneinfo directory as a source of data. However, Windows doesn't include such a directory, so the tzinfo-data gem needs to be installed instead. The tzinfo-data gem contains the same zoneinfo data, packaged as a set of Ruby modules.

Rails 在第一次创建应用程序时会生成一个默认的 Gemfile.如果应用程序是在 Windows 上创建的,则将包含 tzinfo-data 的依赖项.但是(从 Rails 版本 4.1.0 开始),这从平台列表中省略了 :x64_mingw,因此不能在 64 位 Windows 版本的 Ruby 上正常工作.这应该在未来的 Rails 版本中修复.

Rails generates a default Gemfile when the application is first created. If the application is created on Windows, then a dependency for tzinfo-data will be included. However (as of Rails version 4.1.0), this omits :x64_mingw from the list of platforms, so doesn't work correctly on 64-bit Windows versions of Ruby. This should be fixed in future Rails releases.

这篇关于TZInfo::DataSourceNotFound 在 Windows 上启动 Rails v4.1.0 服务器时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆