Commit d30da595be74013f16b2fbb728a3ad6c75618b16
1 parent
f9eb0553
Exists in
master
and in
1 other branch
hotfix for question creation with 0 or 1 ideas provided
Showing
2 changed files
with
2 additions
and
1 deletions
Show diff stats
app/controllers/questions_controller.rb
... | ... | @@ -15,7 +15,7 @@ class QuestionsController < InheritedResources::Base |
15 | 15 | def create |
16 | 16 | authenticate |
17 | 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 | 19 | respond_to do |format| |
20 | 20 | format.xml { render :xml => @question.to_xml} |
21 | 21 | end | ... | ... |
app/models/question.rb
... | ... | @@ -62,6 +62,7 @@ class Question < ActiveRecord::Base |
62 | 62 | |
63 | 63 | def ensure_at_least_two_choices |
64 | 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 | 66 | if self.choices.empty? |
66 | 67 | the_ideas.each { |choice_text| |
67 | 68 | item = Item.create!({:data => choice_text, :creator => creator}) | ... | ... |