Skip to content

Instantly share code, notes, and snippets.

@cgoodmac
Created November 24, 2012 16:11
Show Gist options
  • Save cgoodmac/4140325 to your computer and use it in GitHub Desktop.
Save cgoodmac/4140325 to your computer and use it in GitHub Desktop.
Creating answers to questions
def create
q = Question.create(params[:question])
@auth.questions << q
binding.pry
params[:answers].each do |answer_hash|
a1 = Answer.create(answer_hash.to_param)
q.answers << a1
end
redirect_to questions_path
end
Parameters:
{"utf8"=>"✓",
"authenticity_token"=>"8EGP4ThxdelvBt2s4AHcpVCBkdSsyPVOYj8a44X7QuQ=",
"question"=>{"question_text"=>"Hi"},
"answers"=>[{"answer_text"=>"hello",
"is_correct"=>"on"},
{"answer_text"=>"hey"},
{"answer_text"=>""},
{"answer_text"=>""},
{"answer_text"=>""}],
"commit"=>"Create Question"}
@nilbus
Copy link

nilbus commented Nov 24, 2012

{ 'answer_text' => 'Never'
  'is_correct' => true }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment