浏览代码

Show turnout for each election on body detail page

tags/last-sinatra-version
Adrian Short 8 年前
父节点
当前提交
28e03c45af
共有 2 个文件被更改,包括 27 次插入1 次删除
  1. +19
    -1
      app.rb
  2. +8
    -0
      views/body.haml

+ 19
- 1
app.rb 查看文件

@@ -189,8 +189,26 @@ end

get '/bodies/:body/?' do
@body = Body.first(:slug => params[:body])
@elections = Election.all(:body => @body, :order => [:d.desc])
@districts = District.all(:body => @body, :order => [:name])
@elections = repository(:default).adapter.select("
SELECT
e.id,
e.kind,
e.d,
SUM(p.ballot_papers_issued)::float / SUM(p.electorate) * 100 AS turnout_percent
FROM elections e
LEFT JOIN polls p
ON e.id = p.election_id

WHERE e.body_id = ?

GROUP BY p.election_id, e.id
ORDER BY e.d DESC
", @body.id)
haml :body
end



+ 8
- 0
views/body.haml 查看文件

@@ -7,6 +7,11 @@
%h2 Elections

%table
%thead
%tr
%th
%th
%th turnout
- @elections.each do |election|
%tr
%td
@@ -14,6 +19,9 @@
= short_date(election.d)
%td
= election.kind
%td.right
- if election.turnout_percent
= format_percent(election.turnout_percent)
%h2
= @body.districts_name.capitalize


正在加载...
取消
保存