Get value of a hidden field tag Ruby on Rails -
i lost, not know i'm doing wrong! have 4 radio buttons , hidden field (value = "1"). when click on second radiobutton, value of hidden field changes 2 , on. works fine js function.
different divs showed when different radiobutton selected. now, when i'm trying value of hidden field in controller returns nil.
here's code:
view:
(radiobuttons, hiddenfield , 1 div)
<div> <%= form_tag patients_path %> <%= 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' %> <p> <%= text_field_tag :search1, params[:search1] %> <%= submit_tag "search", :name => nil %> </p> <% end %> </div>
controller:
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
it's because have 2 forms. when submit second form won't send fields of first form. if put in 1 form work expected.
Comments
Post a Comment