Hi... @list.each do |f| chatfile = ChatfileInfo.find_all_by_id(f.chat_id) end Is it possible to simplyfy the array iteration in one line... 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
2010/1/19 Newb Newb <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>:> Hi... > > @list.each do |f| > > chatfile = ChatfileInfo.find_all_by_id(f.chat_id) > > end > > Is it possible to simplyfy the array iteration in one line...@list.each { |f| chatfile = ChatfileInfo.find_all_by_id(f.chat_id) } There is not much point, whether one line or several, though as at the end chatfile will be set to the last one so this would be better chatfile = ChatfileInfo.find_all_by_id(@list.last.chat_id) if @list.last and what is this find_all_by_id anyway, should that be find_by_id? Colin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Jan 19, 2010, at 6:12 AM, Colin Law wrote:> 2010/1/19 Newb Newb <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>: >> Hi... >> >> @list.each do |f| >> >> chatfile = ChatfileInfo.find_all_by_id(f.chat_id) >> >> end >> >> Is it possible to simplyfy the array iteration in one line... > > @list.each { |f| chatfile = ChatfileInfo.find_all_by_id(f.chat_id) } > > There is not much point, whether one line or several, though as at the > end chatfile will be set to the last one so this would be better > > chatfile = ChatfileInfo.find_all_by_id(@list.last.chat_id) if > @list.last > > and what is this find_all_by_id anyway, should that be find_by_id? > > ColinWell, guessing a bit about what you mean: Given a list of things having a chat_id, find all the ChatfileInfo records that correspond. And building on Colin''s question, I''m assuming that the ChatfileInfo#id is the primary key. chatfile = ChatfileInfo.find(@list.map(&:chat_id)) Now this might not be anything close to what you really want. If your entire loop is represented by your original post, then Colin''s simplification is right. What are you *really* trying to do? -Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi Try to apply the proper model relation ship.That will be more easier Sijo -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.