Well i tried what you said, and it worked.
one thing though. I have multiple items in my category column in the
db, seperated by spaces.. and this is what i tried, with no luck if
there are more than one item.
def find_all_by_category(item)
self.find(:all, :params => {:category => /#{item}/})
end
Just incase anyone was wondering, this is what i came up with after
more reading of the api and spending some time on freenode, hope it
helps you.
def self.find_all_by_category(item)
self.find( :all, :conditions => ["category like ?", "%#{item}%"] )
end
That looks good! Glad you got it working. Basically, it's a way to do
matches on substrings of category. I.e. if I have a category of "Car"
I could do: Prop.find_all_by_category("ar") and it would match "Car"
and anything else like that.
The one thing I'd caution you on: this may end up being confusing in
the future. "find_all_by_X" (where X is some attribute on that model)
is already part of AR associations. So you are redefining an existing
method to work differently, which may confuse you or mess you up
later. My recommendation is to call it something differently, maybe
like: find_by_category_substring(item).