The page I'm working on has 10 different blurbs of text that I need to retrieve. Are you saying it's faster to make 10 queries than to make 1 query and convert it to a hash using index_by?

On Apr 11, 2007, at 10:07 PM, Leon Yeh wrote:

Hi Javan, this probably not going to do what you want but I found using with_scope create a more readable code, not to mention I think it would be resulted a better performance than going thru hash one by one, especially when the resulting hash is a large one. Database is designed to handle search better than going thru the hash in linear fashion.

http://media.railscasts.com/videos/005_using_with_scope.mov

Watch this screencast, and let me know what do you think?

Leon Yeh
New Avenue Systems Inc.
Office: (626)254-1757 x880
[EMAIL PROTECTED]
Imagination Delivered. www.newavenue.net




Javan Makhmali wrote:
Even better!

On Apr 11, 2007, at 9:51 PM, John Parker wrote:

On 4/11/07, Javan Makhmali <[EMAIL PROTECTED]> wrote:
I'd love to do

@blurbs = Blurb.find(:all)

@about_blurb = @blurbs.give_me_the_one_where_name_is('about')

ActiveSupport adds #index_by to Enumerable which seems like it might
be useful here:

<URL:http://api.rubyonrails.org/classes/Enumerable.html#M001100>

@blurbs = Blurb.find(:all).index_by(&:name)

@blurbs would be a Hash keyed on the blurb names, allowing you to grab
@blurbs['about'], @blurbs['contact'], etc.

-John

--
John Parker
[EMAIL PROTECTED]
_______________________________________________
Sdruby mailing list
[EMAIL PROTECTED]
http://lists.sdruby.com/mailman/listinfo/sdruby

--------------------------------------------------------------------- ---

_______________________________________________
Sdruby mailing list
[EMAIL PROTECTED]
http://lists.sdruby.com/mailman/listinfo/sdruby

_______________________________________________
Sdruby mailing list
[EMAIL PROTECTED]
http://lists.sdruby.com/mailman/listinfo/sdruby

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________
Sdruby mailing list
[EMAIL PROTECTED]
http://lists.sdruby.com/mailman/listinfo/sdruby

Reply via email to