aboutsummaryrefslogtreecommitdiff
path: root/site
diff options
context:
space:
mode:
Diffstat (limited to 'site')
-rw-r--r--site/app/models/agenda.rb13
-rw-r--r--site/app/models/agenda_item.rb12
2 files changed, 13 insertions, 12 deletions
diff --git a/site/app/models/agenda.rb b/site/app/models/agenda.rb
index 75a9a23..29c57f5 100644
--- a/site/app/models/agenda.rb
+++ b/site/app/models/agenda.rb
@@ -78,18 +78,7 @@ class Agenda < ActiveRecord::Base
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
+ item.update_voting_options(item_info[1])
end
end
diff --git a/site/app/models/agenda_item.rb b/site/app/models/agenda_item.rb
index 938e2e1..e8874ff 100644
--- a/site/app/models/agenda_item.rb
+++ b/site/app/models/agenda_item.rb
@@ -56,6 +56,18 @@ class AgendaItem < ActiveRecord::Base
return acting_user == user if [nil, :title, :discussion, :body].include?(field)
end
+ def update_voting_options(new_descriptions)
+ old_descriptions = voting_options.*.description
+
+ (old_descriptions - new_descriptions).each do |description|
+ option = VotingOption.agenda_item_id_is(id).description_is(description).first
+ option.destroy
+ end
+
+ (new_descriptions - old_descriptions ).each do |description|
+ VotingOption.create! :agenda_item => self, :description => description
+ end
+ end
protected
# Updated discussion time for a single agenda item
# protected because we want to call it only from