ktulasi
Joined: 21 Oct 2009 Posts: 55
|
Posted: Tue Dec 15, 2009 12:02 pm Post subject: Finding repeatedly entered customers in a list |
|
|
I need to display customers list in such a way that the order should be in repeatedly entered customers in the list.
I am having tables customer and callinformation.and the relatiion between the models is:
class Customer
has_many :call_informations,:foreign_key => 'customer_id'
end
class Callinformation
belongs_to :customer , :foreign_key => 'customer_id'
end
now i need to get the mostly entered customers from the callinformation table.
In controller , write as
def list
@call_infos =CallInformation.paginate :page => params[:page], :order => 'temp DESC', :per_page =>5, :select => "count(*) AS temp, customer_id", :group => "customer_id"
end
here 'group' retrieve a list with unique customers from our customers table, and ":select => "count(*) AS temp " will store the value of count in temp variable. and :order =>'temp DESC" will take value of count in descending order.
and in view
<%= @call_info.temp %> |
|