I''m using the "rubilicious" gem to integrate delicious into my site, and it''s working fine. However, the items are out of order. It pulls the most recent 10 posts, but not in descending order. This is what I''m doing: def setup_rubilicious require ''rubilicious'' r = Rubilicious.new(''user'',''pass'') @d_links = Array.new @d_descs = Array.new @d_times = Array.new @per_page = 10 bookmarks = r.recent(''rpheath'',@per_page) bookmarks.each do |post| @d_links << post[''href''] @d_descs << post[''description''] @d_times << post[''time''] end end So, essentially I need to sort @d_links, @d_descs, @d_times according to the date in descending order, so they all match up. Is there a better way to do this than use 3 variables? It would be ideal to have one variable, and refer to the "time" or "description" or "href". Something like: @delicious.each do |post| <a href="<%= post["href"] %>" title="<%= post["time"] %>"><%= post["description"] %></a> <br /> end But if that''s not possible, what is the best way to sort all three variables based on the time??? Thanks! -- 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 -~----------~----~----~----~------~----~------~--~---
I didn''t understand where the date was (assuming it''s post[''time'']), but sort_by is a cool thing: bookmarks = r.recent(''rpheath'',@per_page).sort_by { |post| post[''time''] } Vish On 9/21/06, ry an <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > I''m using the "rubilicious" gem to integrate delicious into my site, and > it''s working fine. However, the items are out of order. It pulls the > most recent 10 posts, but not in descending order. This is what I''m > doing: > > def setup_rubilicious > require ''rubilicious'' > r = Rubilicious.new(''user'',''pass'') > @d_links = Array.new > @d_descs = Array.new > @d_times = Array.new > @per_page = 10 > bookmarks = r.recent(''rpheath'',@per_page) > bookmarks.each do |post| > @d_links << post[''href''] > @d_descs << post[''description''] > @d_times << post[''time''] > end > end > > So, essentially I need to sort @d_links, @d_descs, @d_times according to > the date in descending order, so they all match up. Is there a better > way to do this than use 3 variables? It would be ideal to have one > variable, and refer to the "time" or "description" or "href". Something > like: > > @delicious.each do |post| > <a href="<%= post["href"] %>" title="<%= post["time"] %>"><%> post["description"] %></a> <br /> > end > > But if that''s not possible, what is the best way to sort all three > variables based on the time??? Thanks! > > -- > 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 -~----------~----~----~----~------~----~------~--~---
Thanks! That worked perfectly. I actually needed the reverse list, but that''s also easy using: bookmarks.reverse.each do |b| Thanks again... -- 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 -~----------~----~----~----~------~----~------~--~---
On Sep 21, 2006, at 2:07 PM, ry an wrote:> > Thanks! That worked perfectly. I actually needed the reverse > list, but > that''s also easy using: > > bookmarks.reverse.each do |b| > > Thanks again... >If the time is a number, then negate it for the sort_by: bookmarks = r.recent(''rpheath'',@per_page).sort_by { |post| - post [''time''] } -Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org