开发者

Using gems in Rails 3

I am new to Ruby and Rails so this question might be trivial, but

How can you include/use a gem in Rails?

Do you just put "gem '

What do you do after that?

If this procedure is correct, when I try to run 'rails server' it spits out this error

/.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)

What am I doing wrong?开发者_运维知识库

Ruby 1.9.2 Rails 3 RubyGem 1.3.7 Gem i'm trying to use 'contacts' 1.2.4

Thanks guys, Sean Chan


I had the same issue, here is how I fixed it:

In case you havent already, put gem 'contacts' in your Gemfile and run

bundle install

Ruby >= 1.9 doesn't have jcode, a module to handle japanese (EUC/SJIS) strings, as it supports unicode natively.

So you will need to add: require 'jcode' if RUBY_VERSION < '1.9' to your gdata gem found under your .rvm directory somewhere similar to this:

/home/.rvm/gems/ruby-1.9.2-p0@your_gemset_name/gems/gdata-1.1.1/lib/gdata.rb

change line 21 to:

if RUBY_VERSION < '1.9'
  require 'jcode'
  $KCODE = 'UTF8'
end

As I'm also a noob how would I go about letting the author of the gdata gem know about this?


To use a Gem in Rails 3 you need to specify it in the Gemfile and use bundler to install the dependency. Here's a few resources to learn more about Bundler and Rails 3

  • Checking out the Rails 3 Beta, Part I: Bundler
  • Bundler Website
  • Bundler RailsCast


I had the same problem. Updated to ruby 1.9.2 and the problem stopped.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜