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

  • Home
  • SEARCH
  • 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 3600562
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:30:40+00:00 2026-05-18T20:30:40+00:00

I have searched endlessly for a solution to this and I thought i had

  • 0

I have searched endlessly for a solution to this and I thought i had solved it when I got an image to display. However the thumbnail was only the one stored in the root element. Quite simply this works:

rss = Nokogiri::XML(open('http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/front_page/rss.xml'))
@news = rss.xpath('//item').map do |i|
  {
    'title'       => i.xpath('title').text, 
    'link'        => i.xpath('link').text, 
    'description' => i.xpath('description').text,
    'thumbnail'   => i.xpath('//media:thumbnail').attr('url')
  }
end

But editing the media:thumbnail to reference that item seems to break it:

{
  'title'       => i.xpath('title').text, 
  'link'        => i.xpath('link').text, 
  'description' => i.xpath('description').text,
  'thumbnail'   => i.xpath('media:thumbnail').attr('url')
}

I don’t understand why as both elements are identical. Any pointers in the right direction would be appreciated.

Thanks!

  • 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-05-18T20:30:41+00:00Added an answer on May 18, 2026 at 8:30 pm

    Your code breaks at the first element that doesn’t have a thumbnail child element. Try this:

    @news = rss.xpath('//item').map do |i|
      thumb = i.at_xpath('media:thumbnail').attr('url') if i.at_xpath('media:thumbnail')
      {
        'title' => i.at_xpath('title').text, 
        'link' => i.at_xpath('link').text, 
        'description' => i.at_xpath('description').text,
        'thumbnail' => thumb
      }
    end
    

    Now thumbnail will either be the URL if it exists or nil if it doesn’t.

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

Sidebar

Related Questions

I have searched endlessly for a solution to this and I thought i had
(have searched, but not been able to find a simple solution to this one
I have searched hi and low for a solution for this, basicly I would
I have searched endlessly to no avail on this, hopefully someone can help! I
I have searched and searched for a solution to this problem, but it seems
I have searched high and low for this solution. Any insights will be highly
I have searched around for an answer to this but can't find one. When
I have searched around for a while and had a go at tweaking this
I have searched this site extensively but cannot find a solution. Here is the
I have searched far and wide on this one, but haven't really found a

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.