-2

very new to coding so, having exhausted Google and Stack Overflow, would really appreciate some advice...

I am currently building a web-scraper to get familiar with CMD vs Sublime Text, feeling Ruby in action; So i am working my way through this tutorial

After having actioned in CMD

C:\gem install HTTParty

SUBLIME TEXT - starts with this code:

require_relative 'HTTParty' 
require_relative 'Nokogiri' 

etc

But before i can get to anything more from CMD, i hit web_scraper.rb and it returns with:

C:/Users/ATH18/Desktop/nokogiri_tutorial/web_scraper.rb:1:in `require_relative': cannot load such file -- C:/Users/ATH18/Desktop/nokogiri_tutorial/httparty (LoadError)
from C:/Users/ATH18/Desktop/nokogiri_tutorial/web_scraper.rb:1:in `<main>'

[Finished in 0.1s with exit code 1]

I think this has to be due to one of the following:

i) maybe gems have to have their actual files dragged into whatever folder you're creating a new program in? ii) i'm missing another piece of information that would let it run properly? iii) perhaps there's another way to tell CMD/ruby that the "require"d gem is not in the current folder (I read this somewhere but their advice didnt seem to work either).

NOTE - i have done gem install xxxxxx in both the C:\ directory and C:\users\desktop\projectFolder\

Help?

Aid19801
  • 1,175
  • 1
  • 17
  • 30

1 Answers1

0

You have to use require instead of require_relative. The difference between both a is explained here: https://stackoverflow.com/a/3672600/92049


Use require 'GEMNAME' for gems installed with gem install GEMNAME; use require_relative 'PATH' to require a file relative to the file containing require_relative. (Most often you will find yourself using require.)

To come back to your question: As it says in the tutorial, you have to write require 'HTTParty' instead of require_relative 'HTTParty'.

Does this answer your original question?

Community
  • 1
  • 1
sebastian
  • 1,438
  • 1
  • 15
  • 23
  • Ah okay... have removed the require. But now getting: `code` SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (OpenSSL::SSL::SSLError) `code` – Aid19801 Jan 25 '16 at 14:16
  • @NewbieAid Now that the problem in this question has fixed, it has uncovered a new problem. That new problem should be asked about in a new question. – Wayne Conrad Jan 31 '16 at 14:03
  • Thanks Wayne - solved the issues by adding the gem name into the gem file manually, via Notepad. – Aid19801 Feb 06 '16 at 12:20