I want to parse multiple feeds but i have ran into problems Im doing a query on a table which returns rss feed urls stored in an instance variable called @urls . with each of these eed urls i want to parse them like below @feeds = SimpleRSS.parse open(@urls.feed_url) however this only works when doing a query for first or last and not find:all. eg: just 1 feed url undefined method `feed_url'' for #<Array:0x7f97c3f4faf8> any suggestions on what the problem is? ive tried the approach of trying to put this into a loop but had no luck and are struggling to find a solution Regards nick -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 12 Apr., 18:59, Nick Hoyle <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I want to parse multiple feeds but i have ran into problems > > Im doing a query on a table which returns rss feed urls stored in an > instance variable called @urls . > > with each of these eed urls i want to parse them like below > > @feeds = SimpleRSS.parse open(@urls.feed_url) > > however this only works when doing a query for first or last and not > find:all. eg: just 1 feed url > > undefined method `feed_url'' for #<Array:0x7f97c3f4faf8> > > any suggestions on what the problem is? ive tried the approach of trying > to put this into a loop but had no luck and are struggling to find a > solutionTo me the problem is pretty obvious. You are trying to call an undefined method ''feed_url'' on an Array. To make this work you should call the method on each of the items in the Array individually. Like this: @feeds = [] @urls.each do |url| @feeds << SimpleRSS.parse open(url.feed_url) end You need to know, that whenever you''re asking ActiveRecord for multiple records in the database, they will always come back as an Array with each item representing a record or model. But when you''re asking for just a single record (Model.find(:first) or Model.find (:last)) you simply get the record/model back. -- Best regards, David Knorr http://twitter.com/rubyguy --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
hi thanks for the reply, was much needed. I knew what i was trying to do which was like you say call each of the items in the array i just wasnt sure how to do it, and attempted a similar type of loop but had no luck. I will look into this and see if i can achieve what i want Thanks alot nick -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Nick Hoyle wrote:> hi thanks for the reply, was much needed. > > I knew what i was trying to do which was like you say call each of the > items in the array i just wasnt sure how to do it, and attempted a > similar type of loop but had no luck. > > I will look into this and see if i can achieve what i want > > Thanks alot > > nickjust another quick question how would i able to output each parsed feed from the array @feeds[] in a view? -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 12 Apr., 22:02, Nick Hoyle <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Nick Hoyle wrote: > > hi thanks for the reply, was much needed. > > > I knew what i was trying to do which was like you say call each of the > > items in the array i just wasnt sure how to do it, and attempted a > > similar type of loop but had no luck. > > > I will look into this and see if i can achieve what i want > > > Thanks alot > > > nick > > just another quick question > > how would i able to output each parsed feed from the array @feeds[] in a > view?You would do something like this: <ul id="feeds"> <%- @feeds.each do |feed| -%> <li><%= feed.channel.title %></li> <%- end -%> </ul> Voila, a list of feed titles. :) -- Best regards, David Knorr http://twitter.com/rubyguy --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---