Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 340
Sean Chan Avatar asked Nov 07 '10 23:11

Sean Chan


People also ask

What is the best authentication gem for rails?

The best authentication gem If you are building a Rails API, then you will probably need token-based authentication and that is when Devise Token Auth comes in. This gem is built on top of Devise, one of the most popular authentication gems for Rails which you may have already worked with.

What is Ruby on rails?

Ruby on Rails is a full-stack web framework optimized for programmer happiness and sustainable productivity. It encourages beautiful code by favoring convention over configuration.

What is devise token AUTH for rails?

If you are building a Rails API, then you will probably need token-based authentication and that is when Devise Token Auth comes in. This gem is built on top of Devise, one of the most popular authentication gems for Rails which you may have already worked with. If that’s the case, then you’ll get familiar with Devise Token Auth very easily.

What are the best gems to use for factories?

Another gem that we find very useful for factories is Faker, as it provides an easy way to generate fake data. Last but not least, if your API relies on third party services you will need stubbing on the external HTTP requests and for this I recommend using Webmock.


Video Answer


2 Answers

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?

like image 70
pagetribe Avatar answered Oct 07 '22 16:10

pagetribe


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
like image 45
Simone Carletti Avatar answered Oct 07 '22 18:10

Simone Carletti