Attempt to add ordering scope to last_action
This commit is contained in:
parent
1bcb9d4bb1
commit
07640c2164
2 changed files with 3 additions and 3 deletions
2
app.rb
2
app.rb
|
@ -12,7 +12,7 @@ get '/' do
|
||||||
end
|
end
|
||||||
|
|
||||||
leaders = Leader.all.includes(:last_attack, :last_defense)
|
leaders = Leader.all.includes(:last_attack, :last_defense)
|
||||||
@top20 = leaders.select { |l| l.last_action }.sort_by { |l| l.last_action } + leaders.reject { |l| l.last_action }
|
@top20 = leaders.reject { |l| l.last_action } + leaders.select { |l| l.last_action }.sort_by { |l| l.last_action }.reverse
|
||||||
|
|
||||||
erb :index
|
erb :index
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
class Leader < ActiveRecord::Base
|
class Leader < ActiveRecord::Base
|
||||||
has_one :last_attack, foreign_key: :attacker, primary_key: :leader, class_name: 'Raid'
|
has_one :last_attack, -> { order created_at: :desc }, foreign_key: :attacker, primary_key: :leader, class_name: 'Raid'
|
||||||
has_one :last_defense, foreign_key: :defender, primary_key: :leader, class_name: 'Raid'
|
has_one :last_defense, -> { order created_at: :desc }, foreign_key: :defender, primary_key: :leader, class_name: 'Raid'
|
||||||
|
|
||||||
def last_action
|
def last_action
|
||||||
if last_attack == nil && last_defense == nil
|
if last_attack == nil && last_defense == nil
|
||||||
|
|
Loading…
Reference in a new issue