运行Rails服务器时缺少“jcode”宝石

11

当我尝试运行'rails server'时,它会给出一个错误,说它找不到'jcode',而我认为jcode是Ruby的默认库。 你们有什么线索吗?

/Users/seanfchan/.rvm/gems/ruby-1.9.2-p0@global/gems/gdata-1.1.1/lib/gdata.rb:21:in `require': no such file to load -- jcode (LoadError)
 from /Users/seanfchan/.rvm/gems/ruby-1.9.2-p0@global/gems/gdata-1.1.1/lib/gdata.rb:21:in `<top (required)>'
 from /Users/seanfchan/.rvm/gems/ruby-1.9.2-p0@global/gems/contacts-1.2.4/lib/contacts/gmail.rb:1:in `require'
 from /Users/seanfchan/.rvm/gems/ruby-1.9.2-p0@global/gems/contacts-1.2.4/lib/contacts/gmail.rb:1:in `<top (required)>'
 from /Users/seanfchan/.rvm/gems/ruby-1.9.2-p0@global/gems/contacts-1.2.4/lib/contacts.rb:6:in `require'
 from /Users/seanfchan/.rvm/gems/ruby-1.9.2-p0@global/gems/contacts-1.2.4/lib/contacts.rb:6:in `<top (required)>'
 from /Users/seanfchan/.rvm/gems/ruby-1.9.2-p0@global/gems/bundler-1.0.3/lib/bundler/runtime.rb:64:in `require'
 from /Users/seanfchan/.rvm/gems/ruby-1.9.2-p0@global/gems/bundler-1.0.3/lib/bundler/runtime.rb:64:in `block (2 levels) in require'
 from /Users/seanfchan/.rvm/gems/ruby-1.9.2-p0@global/gems/bundler-1.0.3/lib/bundler/runtime.rb:62:in `each'
 from /Users/seanfchan/.rvm/gems/ruby-1.9.2-p0@global/gems/bundler-1.0.3/lib/bundler/runtime.rb:62:in `block in require'
 from /Users/seanfchan/.rvm/gems/ruby-1.9.2-p0@global/gems/bundler-1.0.3/lib/bundler/runtime.rb:51:in `each'
 from /Users/seanfchan/.rvm/gems/ruby-1.9.2-p0@global/gems/bundler-1.0.3/lib/bundler/runtime.rb:51:in `require'
 from /Users/seanfchan/.rvm/gems/ruby-1.9.2-p0@global/gems/bundler-1.0.3/lib/bundler.rb:112:in `require'
 from /Users/seanfchan/RubyPractice/gettingContancts/config/application.rb:7:in `<top (required)>'
 from /Users/seanfchan/.rvm/gems/ruby-1.9.2-p0@global/gems/railties-3.0.1/lib/rails/commands.rb:28:in `require'
 from /Users/seanfchan/.rvm/gems/ruby-1.9.2-p0@global/gems/railties-3.0.1/lib/rails/commands.rb:28:in `block in <top (required)>'
 from /Users/seanfchan/.rvm/gems/ruby-1.9.2-p0@global/gems/railties-3.0.1/lib/rails/commands.rb:27:in `tap'
 from /Users/seanfchan/.rvm/gems/ruby-1.9.2-p0@global/gems/railties-3.0.1/lib/rails/commands.rb:27:in `<top (required)>'
 from script/rails:6:in `require'
 from script/rails:6:in `<main>'

操作系统: Mac OSx Snow Leopard
Ruby版本: RVM 1.9.2
Rails版本: 3.0.1
Gem版本: 1.3.7
尝试使用'contacts' gem

谢谢,
Sean Chan

3个回答

17

看起来你使用的库没有更新到 Ruby 1.9 的版本。

Ruby >= 1.9 不再需要 jcode 模块来处理日语(EUC/SJIS)字符串,因为它能够原生支持 Unicode。

你可能想要查看一下是否有该库的更新版本,否则你可以查看源代码并找到需要 jcode 的位置,并将其替换为

require 'jcode' if RUBY_VERSION < '1.9'

我是 Ruby 的新手,也遇到了同样的错误。请问您能告诉我应该把这段代码放在哪个文件中吗? - Bongs
@Bongs:错误信息告诉你具体是哪个文件和哪一行。 - Mark Thomas

5
我们应该检查gdata gem文件下的lib文件夹。
添加这行代码:
require 'jcode' if RUBY_VERSION < '1.9'

lib/gdata.rb文件中。


2

另一个解决方案是将以下内容添加到您的Gemfile中:

gem 'gdata_19', '1.1.5'
gem 'contacts', :git => 'git@github.com:eofferma/contacts.git'

我刚刚不得不切换到:gem 'gdata_19','1.1.5'。 - whizcreed

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接