From: Greg Ma Date: 2010-02-16T15:17:23+09:00 Subject: Re: Find by association table Josh Cheek wrote: > On Mon, Feb 15, 2010 at 11:49 PM, Greg Ma > wrote: > >> #method >> > Greg >> >> -- >> Posted via http://www.ruby-forum.com/. >> >> > Based on the similar topic to your previous post, which seemed to be a > Rails > application (if you recall, I suggested you would have more luck at the > Rails mailing list http://groups.google.com/group/rubyonrails-talk ), I > would suggest that you should have an association between students and > tags. > Probably a has_and_belongs_to_many association through a join table ( > http://guides.rubyonrails.org/association_basics.html#the-has-and-belongs-to-many-association). It is a he-has-and-belongs-to-many-association > If this is the case, then you should be able to simply say: > def find_students_by_tag(tag) > tag.students > end No i cannot do this because the parameter isnt a tag object but just a string. I guess i could try this def find_students_by_tag(tag) res = Tag.find_by_name(tag) res.students unless res end -- Posted via http://www.ruby-forum.com/.