From af09d09a318f5339c97d24a2e5e18bbaf16a8b7b Mon Sep 17 00:00:00 2001 From: Luke Baker Date: Fri, 27 Jan 2012 15:57:16 -0500 Subject: [PATCH] fix find_or_create_by to workaround new bug in Rails --- app/models/question.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/models/question.rb b/app/models/question.rb index 9cb23d5..64599f5 100644 --- a/app/models/question.rb +++ b/app/models/question.rb @@ -97,7 +97,9 @@ class Question < ActiveRecord::Base logger.info "inside Question#simple_random_choose_prompt" raise NotImplementedError.new("Sorry, we currently only support pairwise prompts. Rank of the prompt must be 2.") unless rank == 2 choice_id_array = distinct_array_of_choice_ids(:rank => rank, :only_active => true) - 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 ]) + prompt = prompts.find_or_initialize_by_left_choice_id_and_right_choice_id(choice_id_array[0], choice_id_array[1]) + prompt.save + prompt end # adapted from ruby cookbook(2006): section 5-11 @@ -119,7 +121,8 @@ class Question < ActiveRecord::Base end target -= weight end - 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 }]) + prompt = prompts.find_or_initialize_by_left_choice_id_and_right_choice_id(left_choice_id, right_choice_id) + prompt.save end generated_prompts.push prompt end -- libgit2 0.21.2