我有一个用于创建问题和答案的新表格。这是我的表格:
<%= simple_form_for [@question_type, @question], url: path, defaults: { error: false } do |question_form| %>
<%= render 'shared/error_messages', object: question_form.object %>
<div class="question_fields well">
<%= question_form.input :content, input_html: { rows: 4, class: 'span6' } %>
<%= question_form.input :mark, input_html: { class: 'span1' } %>
<%= question_form.association :topic %>
</div>
<%= question_form.simple_fields_for :answers do |answer_form| %>
<%= render 'answer', f: answer_form %>
<% end %>
<%= question_form.button :submit, class: "new_resource" %>
<% end %>
该问题有 3 个字段:内容、标记、主题。
这是我create
有问题的控制器操作:
def create
@question = Question.new(params[:question])
@question.question_type_id = params[:question_type_id]
@question.user_id = current_user.id
if @question.save
flash[:success] = "Successfully created question."
redirect_to new_question_type_question_path
else
render 'new'
end
end
我的路线:
resources :question_types, only: [:index] do
resources :questions
end
现在,我想在用户提交创建问题成功后,它会再次显示新表单,但topic
选择会显示刚刚保存的问题主题。我怎样才能做到这一点?