If I'm not misreading your question, you just need to
supply a condition to your find:
@blurbs_by_john =
Blurb.find(:all, :conditions => ["name = ?", "John"])
Or even simpler, use one of the dynamic "find_by..." shortcuts:
@blurbs_by_john = Blurb.find_all_by_name("John")
You could also find on a result collection using ruby itself, but
I just got bit recently when trying to use, I think,
the array#find method. It turns out that rails has
redefined that one to be more like the find() we're all
used to (personally I would prefer that something
fundamental like that had been left alone, but I haven't
done enough rails yet to know whether I'm just not
getting something.)
If you need more details on finding within a collection,
I'll have to dig through my code. I've had to do a bit
of that lately, crafting the yield block a bit to get
things right, but I can't remember what I did off the
top of my head. Hopefully one of the simpler finds
with conditions is what you needed.
-glenn
Javan Makhmali wrote:
I have a page with several blurbs of text that appear in various places
like the footer and sidebar. I'd like to be able to query all of the
blurbs at once ( @blurbs = Blurb.find :all ) and then pick from that
collection and display in the view. Each blurb has a permanent
non-changing name attribute, but I'm not sure how to grab just that one
blurb from @blurbs using this attribute.
Javan
------------------------------------------------------------------------
_______________________________________________
Sdruby mailing list
[EMAIL PROTECTED]
http://lists.sdruby.com/mailman/listinfo/sdruby
_______________________________________________
Sdruby mailing list
[EMAIL PROTECTED]
http://lists.sdruby.com/mailman/listinfo/sdruby