Forum: Ruby on Rails Loop and instance variable problem

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
7af028825f6c0f24554c69b2c93729a0?d=identicon&s=25 Nick Hoyle (hoylen)
on 2009-04-14 16:33
I have a loop for parsing each rss feed

@address.each do |address|
         @feed = SimpleRSS.parse open(address.feed)
       end

the problem is my my instance variable @feed just gets overwritten so
basically it displays the last parsed feed


how can i store each feed without it been overwrited so i can display it
in my view?

regards

nick
5772c599ccab3081e0fffb1d54f3b6de?d=identicon&s=25 Andrew Timberlake (andrewtimberlake)
on 2009-04-14 16:57
(Received via mailing list)
On Tue, Apr 14, 2009 at 4:33 PM, Nick Hoyle
<rails-mailing-list@andreas-s.net> wrote:
>
> how can i store each feed without it been overwrited so i can display it
> in my view?
>
> regards
>
> nick

@feeds = []
@address.each do |address|
  @feeds << SimpleRSS.parse open(address.feed)
end

In your view
@feeds.each do |fee|
  ...
end

Andrew Timberlake
http://ramblingsonrails.com
http://www.linkedin.com/in/andrewtimberlake

"I have never let my schooling interfere with my education" - Mark Twain
7af028825f6c0f24554c69b2c93729a0?d=identicon&s=25 Nick Hoyle (hoylen)
on 2009-04-14 17:01
Andrew Timberlake wrote:
> On Tue, Apr 14, 2009 at 4:33 PM, Nick Hoyle
> <rails-mailing-list@andreas-s.net> wrote:
>>
>> how can i store each feed without it been overwrited so i can display it
>> in my view?
>>
>> regards
>>
>> nick
>
> @feeds = []
> @address.each do |address|
>   @feeds << SimpleRSS.parse open(address.feed)
> end
>
> In your view
> @feeds.each do |fee|
>   ...
> end
>
> Andrew Timberlake
> http://ramblingsonrails.com
> http://www.linkedin.com/in/andrewtimberlake
>
> "I have never let my schooling interfere with my education" - Mark Twain

Hi thanks for quick reply, i tried using << symbol before and it just
gave me a syntax error indicating theres somethings wrong around parse.
open
7af028825f6c0f24554c69b2c93729a0?d=identicon&s=25 Nick Hoyle (hoylen)
on 2009-04-14 17:50
i just tried this with the built in rails rss parser and seems to work
fine. must be an issue with simple rss im guessing.
Ef3aa7f7e577ea8cd620462724ddf73b?d=identicon&s=25 Rob Biedenharn (Guest)
on 2009-04-14 21:04
(Received via mailing list)
On Apr 14, 2009, at 10:55 AM, Andrew Timberlake wrote:
>> basically it displays the last parsed feed
> @feeds = []
> @address.each do |address|
>  @feeds << SimpleRSS.parse open(address.feed)
> end

Or more simply:

@feeds = @address.map {|address| SimpleRSS.parse(open(address.feed)) }

>
> "I have never let my schooling interfere with my education" - Mark
> Twain


-Rob

Rob Biedenharn    http://agileconsultingllc.com
Rob@AgileConsultingLLC.com
This topic is locked and can not be replied to.