Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8315111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:03:02+00:00 2026-06-08T21:03:02+00:00

I’ve been hammering out some methods and testing them in the console. The problem

  • 0

I’ve been hammering out some methods and testing them in the console. The problem is that an error occurs when running on the server. Specifically, the first method below triggers this NoMethod error:

undefined method `text' for nil:NilClass

Here’s the code. It’s from the webpage.rb file, which has a uri column.

def download_page_title
  page_as_xml.at_css('title').text
end

def page_as_xml
  page_as_xml ||= Nokogiri::HTML(open(page_uri))
end

def page_uri
  base_uri = Site.find_by_id(self.site_id).homepage #always has "/" at end
  if self.url == base_uri
    page_uri = base_uri
  else
    page_uri = "#{base_uri}#{self.url}"
  end
end

Any idea what I’m doing wrong? Also, any idea why things go smoothly in console but derail on the server?

EDIT: Here’s an example of what I’m doing in console.

1.9.3p194 :262 > a = Webpage.new( url: "http://www.cnn.com/", site_id:165)
 => #<Webpage id: nil, url: "http://www.cnn.com/", site_id: 165, created_at: nil, updated_at: nil, title: nil> 
1.9.3p194 :263 > a.download_page_title
  Site Load (0.3ms)  SELECT "sites".* FROM "sites" WHERE "sites"."id" = 165 LIMIT 1
 => "CNN.com - Breaking News, U.S., World, Weather, Entertainment & Video News" 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T21:03:03+00:00Added an answer on June 8, 2026 at 9:03 pm

    This means that page_as_xml.at_css is returning nil, and you’re then trying to call .text on that nil object.

    So, figure out why that’s returning nil. For example, does the page you’re downloading not specify a title tag that is accessible via CSS selectors? Is the page blank or return no result? Does it return an error status (something not in the 2xx HTTP status range)?

    To say it another way, there’s probably an upstream difference between the pages you’re using for testing versus what the server is actually getting.

    You might need to handle (or throw an exception, or log/report) pages that return nil from a call to page_as_xml.at_css – that really depends on what your software needs to do.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am currently running into a problem where an element is coming back from
I know there's a lot of other questions out there that deal with this
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.