“Dynamic finders with hash attributes for creation”
February 19, 2009 at 4:32 pm 1 comment
Here’s a typical situation:
tag = Tag.find_by_name(name)
if tag.nil?
tag = Tag.create(:name => name, :creator => current_user)
end
You’d think the way to do that would be with the find_or_create_by_name dynamic finder, but that doesn’t work since there’s no way to search by name only, but create by name and creator. Well, that’s just not right. So here’s what we’ll do:
Tag.find_or_create_by_name(:name => name, :creator => current_user)
It’s not a big deal or something I use every day, but I like it anyway.
Source : google .

Entry filed under: ruby on rails. Tags: .
1.
Mike | March 1, 2009 at 8:27 pm
Just passing by.Btw, your website have great content!
_________________________________
Making Money $150 An Hour