Soldiers lost
This commit is contained in:
parent
1683f24c55
commit
e20c54fed4
3 changed files with 14 additions and 3 deletions
7
app.rb
7
app.rb
|
@ -31,10 +31,11 @@ post '/' do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
get '/bossfight/:username' do
|
get '/bossfight/?:username' do
|
||||||
username = params['username'] ? params['username'] : 'mafiaman'
|
@username = params['username'] ? params['username'] : 'mafiaman'
|
||||||
user_raids = Raid.for_user(username)
|
user_raids = Raid.for_user(@username)
|
||||||
@first_negative = user_raids.first_negative
|
@first_negative = user_raids.first_negative
|
||||||
|
@soldiers_lost_to_date = user_raids.soldiers_lost_to_date(@first_negative.created_at)
|
||||||
|
|
||||||
erb :bossfight
|
erb :bossfight
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,4 +16,8 @@ class Raid < ActiveRecord::Base
|
||||||
def self.first_negative
|
def self.first_negative
|
||||||
where('money < 0').order(:created_at).first
|
where('money < 0').order(:created_at).first
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.soldiers_lost_to_date(date)
|
||||||
|
where('date < ?', date).sum(:soldiers)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,3 +1,9 @@
|
||||||
|
<h2>Bossfight: <%= @username %></h2>
|
||||||
|
|
||||||
<% if @first_negative %>
|
<% if @first_negative %>
|
||||||
Raider who broke the walls: <%= @first_negative.attacker %><br/>
|
Raider who broke the walls: <%= @first_negative.attacker %><br/>
|
||||||
<%end%>
|
<%end%>
|
||||||
|
|
||||||
|
<% if @soldiers_lost_to_date %>
|
||||||
|
Soliders killed before walls broken: <%= @soldiers_lost_to_date %>
|
||||||
|
<% end %>
|
||||||
|
|
Loading…
Reference in a new issue