##
# limit selected items to one page, get ids of first item before/after the page
- def get_page_items(items, includes)
+ def get_page_items(items, includes: [], limit: 20)
id_column = "#{items.table_name}.id"
page_items = if params[:before]
items.where("#{id_column} < ?", params[:before]).order(:id => :desc)
items.order(:id => :desc)
end
- page_items = page_items.limit(20)
+ page_items = page_items.limit(limit)
page_items = page_items.includes(includes)
page_items = page_items.sort.reverse
@params = params.permit(:display_name, :friends, :nearby, :language)
- @entries, @newer_entries_id, @older_entries_id = get_page_items(entries, [:user, :language])
+ @entries, @newer_entries_id, @older_entries_id = get_page_items(entries, :includes => [:user, :language])
end
def show
@params = params.permit(:display_name, :before, :after)
- @comments, @newer_comments_id, @older_comments_id = get_page_items(comments, [:user])
+ @comments, @newer_comments_id, @older_comments_id = get_page_items(comments, :includes => [:user])
end
private
@params = params.permit(:display_name, :tag, :before, :after)
- @traces, @newer_traces_id, @older_traces_id = get_page_items(traces, [:user, :tags])
+ @traces, @newer_traces_id, @older_traces_id = get_page_items(traces, :includes => [:user, :tags])
# final helper vars for view
@target_user = target_user