From 59347cc73ea5a7e7aa0046eabfff7c751b44c2f4 Mon Sep 17 00:00:00 2001 From: Adrian Short Date: Thu, 12 Jan 2012 08:43:45 +0000 Subject: [PATCH] Added links to this election's body and previous/next elections for this body --- app.rb | 4 +++- views/electionsummary.haml | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/app.rb b/app.rb index f090fdd..e2c6472 100644 --- a/app.rb +++ b/app.rb @@ -79,7 +79,9 @@ get '/' do end get '/bodies/:body/elections/:date' do - @election = Election.first(:body => Body.first(:slug => params[:body]), :d => params[:date]) + @body = Body.first(:slug => params[:body]) + @election = Election.first(:body => @body, :d => params[:date]) + @elections_for_this_body = Election.all(:body => @body, :order => [:d]) @total_seats = Candidacy.sum(:seats, :election => @election) @total_votes = Candidacy.sum(:votes, :election => @election) diff --git a/views/electionsummary.haml b/views/electionsummary.haml index ec66b75..e108cad 100644 --- a/views/electionsummary.haml +++ b/views/electionsummary.haml @@ -1,5 +1,30 @@ - @page_title = "#{@election.body.name} #{@election.kind} #{long_date(@election.d)}" +.nav + %p + %a{ :href => "/bodies/#{@election.body.slug}" } + « + = @election.body.name + + - if @elections_for_this_body.size > 1 + %p + - @election_index = @elections_for_this_body.index(@election) + + - unless @election_index == 0 + - @previous_election = @elections_for_this_body[@election_index - 1] + %a{ :href => "/bodies/#{@election.body.slug}/elections/#{@previous_election.d}", :title => "Previous #{@election.body.name} election" }< + «  + = @previous_election.kind + = short_date(@previous_election.d) +     + + - unless @election_index == @elections_for_this_body.size - 1 + - @next_election = @elections_for_this_body[@election_index + 1] + %a{ :href => "/bodies/#{@election.body.slug}/elections/#{@next_election.d}", :title => "Next #{@election.body.name} election" }< + = @next_election.kind + = short_date(@next_election.d) + » + %h1 = @election.body.name = @election.kind