Default model order

Railsters:

Suppose you have a model with no reason to find() in any but one
order. The DRYest way to code that would seem to be overriding find().
ActiveRecord seems to encourage this monkey patching by routing
everything thru find():

http://blog.gwikzone.org/articles/2006/09/05/ruby-on-rails-find-with-default-order

That post leads to this slight improvement:

def Version.find(*args)
args[1] = { :order => “created_on desc” }.merge(args[1] || {}) if
[:all, :first].include?(args[0])
super(*args)
end

The latest version is always at the top of the list.

Comments suggestions improvements?


Phlip
http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs