gpt4 book ai didi

ruby-on-rails - 获取 ruby​​ on rails 中的单选按钮值

转载 作者:太空宇宙 更新时间:2023-11-03 16:51:57 24 4
gpt4 key购买 nike

我创建了一个测验,并以部分形式显示每页一个问题,当我使用创建时,我想要在创建之前检查的单选按钮的值。当我接下来在我的 Controller 中使用 params[:answer] 时,它返回 null.. 谁能帮我得到我检查过的单选按钮的值

提前致谢

<div class = "y">
<% form_for @answer do |f|%>
<div class = "label_field_pair">
<label for "questions">
<%= @ans.ques %>
</label>
</div> <br>
<div class = "label_field_pair2">
<label for "options">
<div id = "option-1">
<%= radio_button_tag "answer", "#{@ans.id}ans1"%><%= @ans.ans1 %>
</div><br>
<div id = "option-2">
<%= radio_button_tag "answer", "#{@ans.id}ans2"%><%= @ans.ans2 %>
</div><br>
<div id = "option-3">
<%= radio_button_tag "answer", "#{@ans.id}ans3"%><%= @ans.ans3 %>
</div><br>
<div id = "option-4">
<%= radio_button_tag "answer", "#{@ans.id}ans4"%><%= @ans.ans4 %>
</div><br>
</label>
</div>
<div class="next">
<%= link_to_remote "Next",
:before => "Element.show('loader')",
:success => "Element.hide('loader')",
:url=>{:controller=>"answers", :action=>"next"},
:with => "'&passed_question=#{@ans.id}&'+'&exam_group_id=#{@exam_group.id}&'"
%>
<% end %>
</div>
<% end %>
</div>

在 Controller 中

def next
@user = current_user
@student = Student.find_by_admission_no(@user.username)
@exam_group = ExamGroup.find_by_id(params[:exam_group_id])
@answer = Answer.new(params[:ans])
@answer.answer = params[:answer]
@answer.exam_group_id = @exam_group.id
@answer.user_id = @user.id
passed_question = params[:passed_question]
@answer.questions_id = passed_question
if @answer.save
@ans = Question.find_by_id(left_random, :conditions => ['id not in (?) && exam_group_id=?',answered, @exam_group])
render(:update) do |page|
page.replace_html 'main', :partial => 'ans', :object => @ans
end
end
end
def ans
@user = current_user
@student = Student.find_by_admission_no(@user.username)
@exam_group = ExamGroup.find(params[:exam_group_id])
@tot_ans = answered.count
@last_ques = (Question.count-1)
render(:update) do |page|
page.replace_html @ans, :partial => 'ans', :object => @ans
end
end

最佳答案

在您的单选按钮输入开始之前您需要“f”,但您的 Controller 代码乍一看看起来效率很低:

 <%= f.radio_button :answer, "#{@ans.id}ans1" %> 

关于ruby-on-rails - 获取 ruby​​ on rails 中的单选按钮值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19380806/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com