diff options
author | Joachim Filip Ignacy Bartosik <jbartosik@gmail.com> | 2011-06-20 17:05:30 +0200 |
---|---|---|
committer | Joachim Filip Ignacy Bartosik <jbartosik@gmail.com> | 2011-06-25 14:12:13 +0200 |
commit | 0467daab52d32c46c3c688245e794ef1ed4e0586 (patch) | |
tree | 8cb79fb22d5b481bc8f085eccc0d7ac900322ef4 /site/app | |
parent | Bot sends information about voting options changes to web application (diff) | |
download | council-webapp-0467daab52d32c46c3c688245e794ef1ed4e0586.tar.gz council-webapp-0467daab52d32c46c3c688245e794ef1ed4e0586.tar.bz2 council-webapp-0467daab52d32c46c3c688245e794ef1ed4e0586.zip |
Application receives data from bot
Diffstat (limited to 'site/app')
-rw-r--r-- | site/app/controllers/agendas_controller.rb | 3 | ||||
-rw-r--r-- | site/app/models/agenda.rb | 19 |
2 files changed, 21 insertions, 1 deletions
diff --git a/site/app/controllers/agendas_controller.rb b/site/app/controllers/agendas_controller.rb index c6865a1..18a178d 100644 --- a/site/app/controllers/agendas_controller.rb +++ b/site/app/controllers/agendas_controller.rb @@ -15,7 +15,8 @@ class AgendasController < ApplicationController def results data = JSON.parse(request.env["rack.input"].read) - Agenda.process_results data + Agenda.update_voting_options data['agenda'] + Agenda.process_results data data['votes'] Participation.mark_participations data end diff --git a/site/app/models/agenda.rb b/site/app/models/agenda.rb index 65f45b4..46cf2d8 100644 --- a/site/app/models/agenda.rb +++ b/site/app/models/agenda.rb @@ -57,6 +57,25 @@ class Agenda < ActiveRecord::Base false end + def self.update_voting_options(options) + agenda = Agenda.current + options.each do |item_info| + item = AgendaItem.first :conditions => { :agenda_id => agenda, :title => item_info.first } + new_descriptions = item_info[1] + old_descriptions = item.voting_options.*.description + + (old_descriptions - new_descriptions).each do |description| + option = VotingOption.first :conditions => { :agenda_item_id => item.id, + :description => description } + option.destroy + end + + (new_descriptions - old_descriptions ).each do |description| + VotingOption.create! :agenda_item => item, :description => description + end + end + end + def self.process_results(results) agenda = Agenda.current for item_title in results.keys |