Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

168
Visualizações
NameError: uninitialized constant Crawler::ScraperService on rails c

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.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Oh, yes. Better never forget the "::" before this kind of call.

Right way:

::Crawler::ScraperService.get_url with the two :: before all the classes.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda