ruby - Rails, 1 form, two buttons. Search and New -
i think i'm trying similar this question in rails. have search form of sorts, instead of 2 separate forms want use 1 text input , have 2 submit buttons, 1 initiates search , other begins creating new work order using parameter form. have implemented second half, can't seem find obvious way it. rails cast seems start @ want, seems rails helpers getting in way more anything. there way without javascript? seems i'm mixing raw html rails erb, suspect can improved well. unless turns out rails can't want mean need resort straight html or javascript? hesitation use javascript/jquery weak them , wouldn't know put js files or name them.
<%= form_tag new_work_order_path, :method => "get", class: "navbar-form navbar-left" %> <div class="form-group"> <%= text_field_tag :client_number, params[:client_number], class: "form-control", placeholder: "enter client number"%> </div> <button type="sumbit" class="btn btn-default">new work order</button> <% end %>
give each button value attribute.
<%= form_tag new_work_order_path, :method => "get", class: "navbar-form navbar-left" %> <div class="form-group"> <%= text_field_tag :client_number, params[:client_number], class: "form-control", placeholder: "enter client number"%> </div> <button type="submit" class="btn btn-default" value="new"> new work order </button> <button type="submit" class="btn btn-default" value="search"> search </button> <% end %>
then in controller method check params[:commit]:
if params[:commit] == "new" # create new workorder else # search existing workorders end
you may want use different controller method name since handling both search , new instead of new.
Comments
Post a Comment