views:

151

answers:

1

Hey Everybody,

I am trying to build a rake tasks, that fetches a product feed and adds it to my db.

task :testme => :environment do
require 'nokogiri'
require 'zlib'
require 'open-uri'


  @url = "http://some_url/filename.xml.gz"
  @source = open((@url), :http_basic_authentication=>[USERID, "PASSWORD"])
  @gz = Zlib::GzipReader.new(@source)
  @result = @gz.read
  @doc = Nokogiri::XML(@result)

  @doc.xpath("//product").each do |item|
    Product.create(:productname => product.css("name").text)
  end

end

So this works fine until

@doc = Nokogiri::XML(@result)

which throws a rake error

File name too long (repeating the content of xml- document)

That's really confusing, because I developed and tested it in a model, where I could read, unzip and search the file and then write the desired fields with put.

Do you have an idea?

Cheers,

Val

A: 

Got it:

require 'rubygems'

was missing.

val_to_many