[Rails] break in a each function

klaas klaas_debeuf at hotmail.com
Wed Mar 1 10:34:37 GMT 2006


i have a method , and i only want the first 10 feeds to be put in the 
database , why doesn't this control structure works , when the counter 
is 10 it has to jump out the iteration

greetz Klaas

def get_feed2(rssfile)
                         # Open the RSS file
			 rssfeed = open(rssfile.url)
			 # Use the built-in REXML module

			 # Read the entire RSS file into memory
			 rssdoc = Document.new rssfeed.read
			 #Extract some header data about the feed
			 title = rssdoc.elements['rss/channel/title'].text
			 link = rssdoc.elements['rss/channel/link'].text
			 counter = 0
			 # Extract each RSS item

		rssdoc.elements.each('rss/channel/item') do |item|
			counter = counter + 1
			@artikel=Article.new
			@artikel.titel = item.elements['title'].text
			@artikel.bronvermelding = item.elements['link'].text
			@artikel.article_type_id = 1
			@artikel.publicatie_on = Time.new
			paragraaf = Paragraaf.new()
			paragraaf.ondertitel = item.elements['title'].text
			paragraaf.tekst =  item.elements['description'].text
			@artikel.bericht = paragraaf.to_html
			@artikel.save
			next unless counter===10
		end

 	end

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


More information about the Rails mailing list