3

New Ruby user and I am completely addicted, LOVE it...but...I have hit a roadblock right out of the gate Have read plenty on the Ruby basics/theory/etc Working my way through "Bastards" Ruby Lessons and I am getting error message when trying to use "rest-client" gem

I enter:

require "rubygems"
require "rest-client"
res = RestClient.get("http://en.wikipedia.org/wiki")
puts res.code
#=> 200

puts res.body
#=> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
#=> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
#=> <html lang="en" dir="ltr" class="client-nojs" xmlns="http://www.w3.org/1999/xhtml">
#=> <head> ...

And get:

LoadError: no such file to load — rest-client

method gem_original_require in custom_require.rb at line 36
method require  in custom_require.rb at line 36
at top level    in gem.rb at line 2
copy output
Program exited with code #1 after 0.06 seconds.

Im sure this is quite basic and feel somewhat embarrassed to ask for help but I have tried every place possible to find a fix

On a Mac OS10

Appreciate your help

  • Hmm, you sure it's not `rest_client` with an underscore? Try changing `require rest-client` to `require rest_client` – potench Dec 14 '12 at 04:36
  • tried that unfortunately it didnt work – user1902953 Dec 14 '12 at 04:38
  • Do `gem install rest-client` then try again – potench Dec 14 '12 at 04:39
  • getting this: NoMethodError: undefined method ‘install’ for main:Object at top level in gem.rb at line 1 copy output Program exited with code #1 after 0.03 seconds. – user1902953 Dec 14 '12 at 04:42
  • Sorry, should have been clearer. In your console I believe you need to install the `rest-client` dependency by first running `gem install rest-client`. It doesn't go in your script, you have to install through the console, then run your script. – potench Dec 14 '12 at 04:46
  • yup, did that but then it gives an error "no such file to load rest-client" – user1902953 Dec 14 '12 at 04:50
  • seems strange, was excited because seemed like ruby and rubygems were properly loaded (finally) but when I try to run a script any script it gets stuck – user1902953 Dec 14 '12 at 04:50
  • In terminal try `gem list` See if `rest-client` is listed. – potench Dec 14 '12 at 05:14
  • bundler (1.2.3) crack (0.3.1) mime-types (1.19) nokogiri (1.5.5) rake (10.0.2) rest-client (1.6.7) rubygems-bundler (1.1.0) rubygems-update (1.8.24) rvm (1.11.3.5) – user1902953 Dec 14 '12 at 05:39

2 Answers2

2

You need to do three things:

1. In your code change require 'rest-client' to require 'rest_client'.

2. make sure the rest-client gem is installed: at the console, go to your project's directory and type

$gem list | grep rest-client

If the gem is installed, the command should return something like rest-client (1.6.7). If that happens, proceed to step #3. If nothing is returned then type:

$gem install rest-client

and wait till the gem is installed.

3. After the gem has been installed, stay on the same command line and run your script from it. If you're running it from within an editor, then start your editor from the same command line, e.g.

$>sublime-text --project mywork.sublime-project &

(assuming sublime-text is in your local bin directory, of course)

RedFred
  • 999
  • 9
  • 20
0

answered this had to cd to proper directory