I'm trying to run a class on rails c for debug in a Rails project - duh - but I keep getting name error messages:
#app/services/scraper_service.rb
module Crawler
class ScraperService
URL_HOST = 'http://quotes.toscrape.com/page/1/'
def initialize(tag)
@tag = tag
end
def self.get_url
agent = Mechanize.new
binding.pry
page = agent.get(URL_HOST)
end
end
end
When I try to instance the class on rails c, I get this:
> Crawler::ScraperService.new('love').get_url
NameError: uninitialized constant Crawler::ScraperService
from (pry):5:in `<main>'
Or without the initialize method (of course, in this case it's out of the code):
> Crawler::ScraperService.get_url
NameError: uninitialized constant Crawler::ScraperService
from (pry):7:in `<main>'
I know it's a little thing, but I'm trying to understand this.
Oh, yes. Better never forget the "::" before this kind of call.
Right way:
::Crawler::ScraperService.get_url with the two :: before all the classes.