【发布时间】:2015-04-28 13:11:48
【问题描述】:
我想在用户单击 8 题多项选择测验的提交按钮时将他们引导至“结果”页面,同时还将他们的答案保存到数据库中。
目前我正在使用“form_for”并传入 current_user。当单击提交时,它因此被定向到用户/显示操作。我想转到详细说明用户结果的页面。我该怎么做呢?
这是我的(非常粗略的测试)表格,到目前为止,有一个选择题(由引导程序设计):
<%= form_for([current_user]) do |f| %>
<p>
<%= text_field(:user, :name) %>
</p>
<div class="btn-group-vertical clearfix form-group" data-toggle="buttons">
<label class="btn btn-primary text-left">
<input name="options" id="option1" type="radio" onclick="multiChoiceClick(1, 1)">A. Always. I'm the leader and should have the final say
</label>
<label class="btn btn-primary text-left">
<input name="options" id="option2" type="radio">B. Sometimes, but I think the group should make decisions if possible
</label>
<label class="btn btn-primary text-left">
<input name="options" id="option3" type="radio">C. I generally don't get involved. The group can make their own decisions without my help
</label>
</div>
<p>
<%= f.submit("Get my results!") %>
</p>
<% end %>
我目前包含带有用户名的 text_field 只是作为测试。
我想知道如何将第一个多项选择题“连接”给用户,但在单击“获取我的结果”时显示结果页面。
我很可能在这段代码中有几处错误。如果我这样做了,并且您有答案,您能否指出我做错了什么并解释做那件事的正确方法?抱歉说得这么具体,但我之前有几个 cmet 只指出问题所在,别无选择。
谢谢。
编辑:
有人要了控制器,所以这里是:
class HomeController < ApplicationController
def index
end
def whattypeofleader
@user = current_user
#@quiz_answer = current_user.quiz_answers(0).build
end
def post_params
params.require(:quiz_answer).permit(:body, :user_id)
end
end
我已将@quiz_answer 注释掉,因为我不确定如何将其与表单相关联。在用户控制器中,用户 has_many :quiz_answers 和 QuizAnswer belongs_to :user
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-4 formbuilder