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 3788968
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:04:55+00:00 2026-05-19T12:04:55+00:00

I have a method in a rails 3 model that parses XML with nokogiri.

  • 0

I have a method in a rails 3 model that parses XML with nokogiri.
How can I call this method in the console in order to test its out.

Here is the whole class (I’m trying to call generate_list):

class Podcast < ActiveRecord::Base

validates_uniqueness_of :name

serialize :hosts

def generate_list

# fetch the top 300 podcasts from itunes
itunes_top_300 = Nokogiri.HTML(open("http://itunes.apple.com/us/rss/toppodcasts/limit=300/explicit=true/xml"))

# parse the returned xml
itunes_top_300.xpath('//feed/entry').map do |entry|
  new_name = entry.xpath("./name").text
  podcast = Podcast.find(:all, :conditions => {:name => new_name})
  if podcast.nil?
    podcast = Podcast.new(
      :name => entry.xpath("./name").text,
      :itunesurl => entry.xpath("./link/@href").text,
      :category => entry.xpath("./category/@term").text,
      :hosts => entry.xpath("./artist").text,
      :description => entry.xpath("./summary").text,
      :artwork => entry.xpath("./image[@height='170']").text      
    )
    podcast.save
  else
    podcast.destroy
  end
end

end

end

Edit: Wow, 1000 views. I hope this question has helped people as much as it helped me. It’s amazing to me when I look back on this that, little more than a year ago, I couldn’t figure out the difference between instance methods and class methods. Now I am writing complex service-oriented applications and backends in ruby, Rails, and many other languages/frameworks. Stack Overflow is the reason for this. Thank you so much to this community for empowering people to solve their problems and understand their solutions.

  • 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-19T12:04:56+00:00Added an answer on May 19, 2026 at 12:04 pm

    It looks like you’re wanting to use this as a class method, and so you must define it like this:

    def self.generate_list
      ...
    end
    

    Then you can call this as Podcast.generate_list.

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

Sidebar

Related Questions

I have a Rails controller action to test. In that action, a method User.can?
I have noticed in Rails console that Model.search_for_ids.size != Model.all.size Moreover Thinking Shpinx method
i have a method in a model that looks like this: def self.super_data self.find(:all,
I have a rails model that looks something like this: class Recipe < ActiveRecord::Base
I have a method I want to call using AJAX in rails but I
In Rails 3.0.9 (Ruby 1.9.2, MySQL) I have a method that is supposed to
In my rails project I have a presenter method that has a helper view
In Ruby on Rails, I have an update method in a controller, that is
I'm using Rails' accepts_nested_attributes_for method with great success, but how can I have it
Note: Using Rails 3.1 and current delayed_job gem. I have a User model that

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.