我迷路了,我不知道我做错了什么!我有 4 个单选按钮和一个隐藏字段(值 =“1”)。当您单击第二个单选按钮时,隐藏字段的值更改为 2,依此类推。这适用于 js 函数。
选择不同的射射线布顿时,将显示不同的DIV。现在,当我试图在我的控制器中获取隐藏字段的值时,它总是返回 nil。
这是代码:
看法:
(单选按钮、隐藏字段和一个 div)
<div>
<%= form_tag patients_path do %>
<%= radio_button_tag 'searchRBN', 'patient', true, :onchange => "checkRadioButton()" %>
<%= label_tag :byPatient_patient, "Patient" %>
<%= radio_button_tag 'searchRBN', 'staff', false, :onchange => "checkRadioButton()" %>
<%= label_tag :byStaff_staff, "Staff" %>
<%= radio_button_tag 'searchRBN', 'ocmw', false, :onchange => "checkRadioButton()" %>
<%= label_tag :byOcmw_ocmw, "OCMW" %>
<%= radio_button_tag 'searchRBN', 'mutuality', false, :onchange => "checkRadioButton()" %>
<%= label_tag :byMutuality_mutuality, "Mutuality" %>
<%= hidden_field_tag :hidden_one, "1" %>
<% end %>
</div>
<div id="searchByPatient">
<%= form_tag patients_path, :method => 'get' do %>
<p>
<%= text_field_tag :search1, params[:search1] %>
<%= submit_tag "Search", :name => nil %>
</p>
<% end %>
</div>
控制器:
def index
@staff_all = Staff.all
@ocmw_all = Ocmw.all
@mutuality_all = Mutuality.all
debugger
if params[:hidden_one] == '1'
@patients = Patient.searchByName(params[:search1])
elsif params[:hidden_one] == '2'
@patients = Patient.searchByStaff(params[:search2])
else
@patients = Patient.all
end
end