Skip to content

Instantly share code, notes, and snippets.

@goomerko
Created January 24, 2014 08:45
Show Gist options
  • Save goomerko/8594062 to your computer and use it in GitHub Desktop.
Save goomerko/8594062 to your computer and use it in GitHub Desktop.
def edit
# Find or create all the answers needed for the selected options
used_option_answers = []
@participate.options.each do |option|
option.option_questions.each do |option_question|
unless @participate.option_answers.where(option_question_id: option_question.id).first
# If the answer doesn't exist then create it
option_answer = OptionAnswer.new(option_question_id: option_question.id, subscription_id: @participate.id)
# we need to bypass the answer validation
option_answer.save(validate: false)
@participate.option_answers << option_answer
used_option_answers << option_answer
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment