I would like to get an array/hash where I can write @image[88] and that would result in "thisimage.jpg". I''ve got: @images = Image.find(:all, :select => "id, real_file_name") result = {} @images.map {|a| result[a.id] = a.real_file_name } I think this is correct, but I don''t know how to get the result from it. It doesn''t work with @images[88]. What am I doing wrong? -- 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 Jun 11, 2008, at 7:23 AM, Pål Bergström wrote:> I would like to get an array/hash where I can write @image[88] and > that > would result in "thisimage.jpg". I''ve got: > > @images = Image.find(:all, :select => "id, real_file_name") > result = {} > @images.map {|a| result[a.id] = a.real_file_name } > > I think this is correct, but I don''t know how to get the result > from it. > It doesn''t work with @images[88]. What am I doing wrong?There may be a more railsey way, but this is a basic Ruby way that should work @images = Image.find(:all, :select => "id, real_file_name") @image_map = {} # <--- should be a better name for this @images.each do |this_image| @image_map.store(this_image.id, this_image.real_file_name) end @image_map[some_id] -- gw --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Greg Willits wrote:> On Jun 11, 2008, at 7:23 AM, P�l Bergstr�m wrote: > >> It doesn''t work with @images[88]. What am I doing wrong? > There may be a more railsey way, but this is a basic Ruby way that > should work > > @images = Image.find(:all, :select => "id, real_file_name") > @image_map = {} # <--- should be a better name for this > @images.each do |this_image| > @image_map.store(this_image.id, this_image.real_file_name) > end > > @image_map[some_id] > > -- gwGreat. 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---