Displaying 1 result from an estimated 1 matches for "question_answer".
2006 Jan 18
22
Creating multiple child objects from the same form
...ce_of :answer, :question_id
end
class Question < ActiveRecord::Base
validates_presence_of :question
has_many :answers
end
############ question controller
def create
@question = Question.new(params[:question])
if @question.save
logger.debug(@question.inspect)
params[:question_answer].each_value do |answer|
@question.answers << Answer.new(:answer => answer)
end
flash[:notice] = ''Question was successfully created.''
redirect_to :action => ''list''
else
render :action => ''new''...