@floyd , SELECT :
class User < ActiveRecord::Base
def self.count_new_users_per_day(cutoff_at)
result = count(:all, :conditions => ["created_at >= ?", cutoff_at],
:group => "DATE(created_at)")
result.default = 0
result
end
end
:
class UsersController < ActionController::Base
def index
@cutoff_at = 30.days.ago.at_midnight
@new_users_by_date = User.count_new_users_per_day(@cutoff_at)
@dates = ((@cutoff_at.to_date) .. (@cutoff_at.to_date >> 1))
end
end
, :
<%= render :partial => "user_count", :collection => @dates, :as => :date %>
<td><%=h date.to_s(:db) %></td>
<td><%= number_with_delimiter(@new_users_by_date[date.to_s(:db)]) %></td>
, SQL , Hash/ResultSet, . Hash , , .