Ok, I am interfacing with the del.icio.us API and I want to collect the links in an @instance variable for my view. But I''m having trouble with that part. Here''s what I have: def get_authenticated(path, http) request = Net::HTTP::Get.new(path) request.basic_auth ''user'', ''pass'' response = http.request(request) response.value response.body end @links = Array.new http = Net::HTTP.new(''api.del.icio.us'', 443) http.use_ssl = true http.start do |http| xml = get_authenticated(''/v1/posts/recent?count=10'', http) REXML:ocument.new(xml).root.get_elements(''post'') .each do |post| link = post.attributes[''href''] @links = link end end See where I''m saying "@links = link"? I''m trying to get that into an array. Then iterate over the array in the view, but it''s not working. It only displays the last of the 10 links returned. Can someone please help with this??? Thanks a lot!!! -- Posted via http://www.ruby-forum.com/.
Oh yeah, and I''ve also tried "@links[i] = link" and then "i++" to go to the next index. Not working still. -- Posted via http://www.ruby-forum.com/.
i would try changing link = post.attributes[''href''] to @links = post.attributes[''href''] i think that would work, but i''m not a genius, clearly. -- Posted via http://www.ruby-forum.com/.
Jon Mr wrote:> > i would try changing > > link = post.attributes[''href''] > > to > > @links = post.attributes[''href''] > > i think that would work, but i''m not a genius, clearly.Thanks, but I''ve tried that as well. Still only displays the last one out of the ten links. Isn''t there a way to "collect" the links? Such as ".collect{post.attributes[''href'']}"? I''ve tried variations of this, but couldn''t get anything to work out. So, I''m still stuck. -- Posted via http://www.ruby-forum.com/.
@links = [] REXML:ocument.new(xml).root.get_elements(''post'') .each do |post| link = post.attributes[''href''] @links << link end - dan -- Dan Kohn <mailto:dan@dankohn.com> <http://www.dankohn.com/> <tel:+1-415-233-1000> On Jul 18, 2006, at 12:58 PM, Ryan Heath wrote:> REXML:ocument.new(xml).root.get_elements(''post'') .each do |post| > link = post.attributes[''href''] > @links = link > end
On Tue, Jul 18, 2006, Ryan Heath wrote:> See where I''m saying "@links = link"? I''m trying to get that into an > array. Then iterate over the array in the view, but it''s not working. It > only displays the last of the 10 links returned. Can someone please help > with this???@links << link Should work like a champ :) Ben
On 7/18/06, Ben Bleything <ben@bleything.net> wrote:> On Tue, Jul 18, 2006, Ryan Heath wrote: > > See where I''m saying "@links = link"? I''m trying to get that into an > > array. Then iterate over the array in the view, but it''s not working. It > > only displays the last of the 10 links returned. Can someone please help > > with this??? > > @links << link > > Should work like a champ :) > > BenAlso, worth noting that there is no auto-increment operator in ruby. So i++ should do some weird things but probably won''t throw an error. The << is equivalent to Array.push in other languages if that helps you understand at all. In ruby it seems like counter variables are largely unused which is a mammoth change but it''s really exciting once you really get into the language. Cheers, Chuck Vose
Chuck Vose wrote:> On 7/18/06, Ben Bleything <ben@bleything.net> wrote: >> Ben > Also, worth noting that there is no auto-increment operator in ruby. > So i++ should do some weird things but probably won''t throw an error. > The << is equivalent to Array.push in other languages if that helps > you understand at all. In ruby it seems like counter variables are > largely unused which is a mammoth change but it''s really exciting once > you really get into the language. > > Cheers, > Chuck VoseThanks a lot everyone, and for the explanation - that clears things up tremendously! -- Posted via http://www.ruby-forum.com/.
On 19/07/2006, at 6:17 AM, Dan Kohn wrote:> @links = [] > REXML:ocument.new(xml).root.get_elements(''post'') .each do |post| > link = post.attributes[''href''] > @links << link > endOr, to be a little more Ruby-ish about it: @links = REXML:document.new(xml).root.get_elements(''post'').map {| post| post.attributes[''href''] }
On 7/18/06, Pete Yandell <pete@notahat.com> wrote:> On 19/07/2006, at 6:17 AM, Dan Kohn wrote: > > > @links = [] > > REXML:ocument.new(xml).root.get_elements(''post'') .each do |post| > > link = post.attributes[''href''] > > @links << link > > end > > Or, to be a little more Ruby-ish about it: > > @links = REXML:document.new(xml).root.get_elements(''post'').map {| > post| post.attributes[''href''] }Hot. And your domainname is awesome! Why is it that Rails app names so often start with a number though?