From 33d1f84878b801cb5403a54a991a38c4b472446d Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Fri, 16 Jan 2009 15:09:46 -0800 Subject: [PATCH] Added a named scope to make history lookups easier, Rate.history_for_user(user). #1915 --- app/models/rate.rb | 8 ++++++++ app/views/users/_rates.html.erb | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/models/rate.rb b/app/models/rate.rb index 4536a9f..71b0283 100644 --- a/app/models/rate.rb +++ b/app/models/rate.rb @@ -5,4 +5,12 @@ class Rate < ActiveRecord::Base validates_presence_of :user_id validates_presence_of :date_in_effect + + named_scope :history_for_user, lambda { |user| + { + :conditions => { :user_id => user.id }, + :order => 'date_in_effect DESC' + } + } + end diff --git a/app/views/users/_rates.html.erb b/app/views/users/_rates.html.erb index 047f8fb..118e0cd 100644 --- a/app/views/users/_rates.html.erb +++ b/app/views/users/_rates.html.erb @@ -1,7 +1,7 @@

Rate History

<%# TODO: Refactor out of the view once there is a hook in the controller (Post 0.8.0). %> <%# Can't expect everyone to upgrade at the moment %> -<% @rates = Rate.find(:all, :conditions => { :user_id => @user.id }) %> +<% @rates = Rate.history_for_user(@user) %>