Reputation: 6550
I have four types of Rawscores I want to display together in a paginated table.
The code looks like:
@facebook_scores_today = Rawscore.where(:channel_string => "Facebook", :project => @project, :created_at.gt => Time.now.beginning_of_day)
@youtube_scores_today = Rawscore.where(:channel_string => "Youtube", :project => @project, :created_at.gt => Time.now.beginning_of_day)
@twitter_scores_today = Rawscore.where(:channel_string => "Twitter", :project => @project, :created_at.gt => Time.now.beginning_of_day)
@influence_scores_today = Rawscore.where(:channel_string => "Influence", :project => @project, :created_at.gt => Time.now.beginning_of_day)
Where Rawscore has a Hash with multiple values as atributes for table depending on :channel_string
.
How should I go about this? Any gems that could help "will_paginate" or "kaminari" ?
Update ( Here is my Rawscore model)
class Rawscore
include Mongoid::Document
include Mongoid::Timestamps::Created #for created_at field
belongs_to :channel
belongs_to :project
field :values, type: Hash
validates :values, :presence => true
end
I want to display the keys-values for the :values Hash in the Rawscore model.
Upvotes: 0
Views: 280
Reputation: 6550
The answer to the question lies in using WillPaginate::Collection to create your own pagination structure.
Here is the rubydoc link: http://rubydoc.info/github/mislav/will_paginate/frames
Upvotes: 0
Reputation: 10018
Kaminari can paginate arrays, but it's not efficient because Active Record will instantiated all retrieved records (I.e if you have 10000 records and want to show only 100, there will be 10000 AR objects in memory)
Kaminari.paginate_array(my_array_object).page(params[:page]).per(10)
Instead you can consider joining your queries and paginate with query
scores_today = Rawscore.where(
:channel_string => ["Facebook", "Youtube", "Twitter", "Influence"],
:project => @project, :created_at.gt => Time.now.beginning_of_day
).page(params[:page])
Upvotes: 1