Added a named scope to make history lookups easier, Rate.history_for_user(user). #1915

This commit is contained in:
Eric Davis
2009-01-16 15:09:46 -08:00
parent 5296368183
commit 33d1f84878
2 changed files with 9 additions and 1 deletions

View File

@@ -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

View File

@@ -1,7 +1,7 @@
<h1>Rate History</h1>
<%# 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) %>
<table class="list memberships">
<thead>