I found a superb example on how to do the above problem - 
http://tinyurl.com/4zl6b9

But now I can't figure out how to save my output to my table.  I am 
following this example exactly so that I can duplicate it for my 
purposes.  I am able to get the output correctly, but I can't save it. 
I get an "undefined method save" error.

See below for Steve's code.


Where can I put my method save to have it save my values to my table?

I tried to replace puts g.to_csv to g.save, but that didn't work.  I 
also tried to replace games << game with game.save, but that didn't work 
either.

I'm still new at figuring out how to convert examples like this to my 
needs.

Any help is greatly appreciated!!!!!



--- code from Steve ---

def parse_games(doc)
   games = []
   doc.search("//[EMAIL PROTECTED]'tablehead']//tr").each do |tr|
      @week = tr.search("/td/a").inner_html if(tr[:class] == 'stathead')
      @date = tr.at("td").inner_html if(tr[:class] == 'colhead')

      teams = []
      tr.at("td").search("a").each do |team|
         teams << team.inner_html
      end

      if(teams.size == 2)
         @time = tr.search("td:eq(1)").inner_html
         game = Game.new()
         game.date = @date
         game.week = @week
         game.time = @time
         game.away_team = teams[0]
         game.home_team = teams[1]
         games << game
      end
   end
   games
end

games = 
parse_games(Hpricot(open("http://sports.espn.go.com/nfl/schedule";)))
games.each do |g|
   puts g.to_csv
end

-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to