Commit af09d09a318f5339c97d24a2e5e18bbaf16a8b7b

Authored by Luke Baker
1 parent 64564bbf

fix find_or_create_by to workaround new bug in Rails

Showing 1 changed file with 5 additions and 2 deletions   Show diff stats
app/models/question.rb
... ... @@ -97,7 +97,9 @@ class Question < ActiveRecord::Base
97 97 logger.info "inside Question#simple_random_choose_prompt"
98 98 raise NotImplementedError.new("Sorry, we currently only support pairwise prompts. Rank of the prompt must be 2.") unless rank == 2
99 99 choice_id_array = distinct_array_of_choice_ids(:rank => rank, :only_active => true)
100   - prompts.find_or_create_by_left_choice_id_and_right_choice_id(choice_id_array[0], choice_id_array[1], :include => [:left_choice ,:right_choice ])
  100 + prompt = prompts.find_or_initialize_by_left_choice_id_and_right_choice_id(choice_id_array[0], choice_id_array[1])
  101 + prompt.save
  102 + prompt
101 103 end
102 104  
103 105 # adapted from ruby cookbook(2006): section 5-11
... ... @@ -119,7 +121,8 @@ class Question < ActiveRecord::Base
119 121 end
120 122 target -= weight
121 123 end
122   - prompt = prompts.find_or_create_by_left_choice_id_and_right_choice_id(left_choice_id, right_choice_id, :include => [{ :left_choice => :item }, { :right_choice => :item }])
  124 + prompt = prompts.find_or_initialize_by_left_choice_id_and_right_choice_id(left_choice_id, right_choice_id)
  125 + prompt.save
123 126 end
124 127 generated_prompts.push prompt
125 128 end
... ...