Fixed sort order of packages and screenshots

Packages are sorted by most visits
Screenshots are sorted by newness
This commit is contained in:
Christoph Haas 2018-08-06 18:41:05 +02:00
parent e0b3721804
commit 8e668603fc
2 changed files with 5 additions and 2 deletions

View file

@ -275,7 +275,7 @@ class PackagesController < ApplicationController
# Return packages matching the criteria given by parameters
def query_packages
packages = Package.includes(:screenshots).order(created_at: :desc)
packages = Package.includes(:screenshots).order(visits: :desc)
# text search
if params[:search].present?

View file

@ -20,7 +20,10 @@ class Package < ApplicationRecord
# I am using "destroy_all" here so that when a package gets destroys the
# callbacks for all dependent screenshots are executed - thus removing the
# screenshot files from disk.
has_many :screenshots, :inverse_of=>:package, :dependent => :destroy
has_many :screenshots,
-> { order(id: :desc) },
:inverse_of=>:package,
:dependent => :destroy
# default_scope {
# order('name ASC')