Gman
unread,Feb 26, 2008, 10:57:52 AM2/26/08Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Cape Town Ruby Brigade
Hey guys
I often come across when working with other people that custom find
methods are created for your models in order to make you controllers
more readable and more understandable, examples : User.find_admin,
News.find_latest, etc
But when you use these methods they should not work like this :
News.find_latest(20)
User.find_admin
I believe these methods should always follow the default find method
convention, ie you should always be able to do things like this :
News.find_latest(:all, :conditions => 'author_id <> 1', :limit => 10)
User.find_admin(:first)
And beside keeping the conventions is so easy :
def find_latest(*args)
with_scope(:find => {:order => 'created_at DESC, id DESC'}) do
find(*args)
end
end
def find_latest(*args)
with_scope(:find => {:conditions => ['admin = ?',true]}) do
find(*args)
end
end
So what do you guys think? Am I just be unnecessary?