Commit d30da595be74013f16b2fbb728a3ad6c75618b16

Authored by Pius Uzamere
1 parent f9eb0553

hotfix for question creation with 0 or 1 ideas provided

app/controllers/questions_controller.rb
@@ -15,7 +15,7 @@ class QuestionsController < InheritedResources::Base @@ -15,7 +15,7 @@ class QuestionsController < InheritedResources::Base
15 def create 15 def create
16 authenticate 16 authenticate
17 logger.info "vi is #{params['question']['visitor_identifier']} and local are #{params['question']['local_identifier']}. all params are #{params.inspect}" 17 logger.info "vi is #{params['question']['visitor_identifier']} and local are #{params['question']['local_identifier']}. all params are #{params.inspect}"
18 - if @question = current_user.create_question(params['question']['visitor_identifier'], :name => params['question']['name'], :local_identifier => params['question']['local_identifier'], :ideas => params['question']['ideas'].lines.to_a) 18 + if @question = current_user.create_question(params['question']['visitor_identifier'], :name => params['question']['name'], :local_identifier => params['question']['local_identifier'], :ideas => (params['question']['ideas'].lines.to_a) rescue [])
19 respond_to do |format| 19 respond_to do |format|
20 format.xml { render :xml => @question.to_xml} 20 format.xml { render :xml => @question.to_xml}
21 end 21 end
app/models/question.rb
@@ -62,6 +62,7 @@ class Question < ActiveRecord::Base @@ -62,6 +62,7 @@ class Question < ActiveRecord::Base
62 62
63 def ensure_at_least_two_choices 63 def ensure_at_least_two_choices
64 the_ideas = (self.ideas.blank? || self.ideas.empty?) ? ['sample idea 1', 'sample idea 2'] : self.ideas 64 the_ideas = (self.ideas.blank? || self.ideas.empty?) ? ['sample idea 1', 'sample idea 2'] : self.ideas
  65 + the_ideas << 'sample choice' if the_ideas.length < 2
65 if self.choices.empty? 66 if self.choices.empty?
66 the_ideas.each { |choice_text| 67 the_ideas.each { |choice_text|
67 item = Item.create!({:data => choice_text, :creator => creator}) 68 item = Item.create!({:data => choice_text, :creator => creator})