当前位置: 动力学知识库 > 问答 > 编程问答 >

Pass variable to Controller when clear button is clicked rails

问题描述:

<%= form_tag({controller: "cc_banker_assignments", action: "index"}, method: "get", class: "form-horizontal") do %>

<div class="col-md-4">

<span class="badge badge-error count-error"></span>

<div class="form-group">

<label for="" class="col-sm-4 control-label">Date of Assignment</label>

<div class="col-sm-7">

<%= text_field_tag "assignment_date", params[:assignment_date], class: "form-control", id: "date-range" %>

</div>

</div>

<div class="form-group" style="margin-bottom: 1.5em;">

<label for="" class="col-sm-4 control-label">Assigned To</label>

<div class="col-sm-7">

<%= select_tag "assigned_to", options_from_collection_for_select(@banker, :id, :name, params[:assigned_to]), class: 'form-control single-select', prompt: "All Bankers" %>

</div>

</div>

<div class="col-sm-8 pull-right" style="margin-top: -0.3em">

<%= submit_tag "Search", :class => "btn btn-default lender-search-btn btn-s-layout" %>

<%= button_tag "Clear", :type => 'reset', :class => "btn btn-primary btn-c-layout clear_button", :onClick => "check_for_cancel" %>

</div>

</div>

</div>

<% end %>

Ok so i have this form and i want to be able to pass a variable to my index method on my controller when i click on the button.

This is because i want my controller to know if the clear button has been clicked and the only way for me to do tht is to pass a variable to my controller index method.

my controller method

def index

@banker = Banker.where("locked_at is null and approved = true").order('name asc')

ap params

if !params[:get_status].nil?

params[:banker_status] = BankerAssignmentStatus.where("assignment_status =? ",params[:get_status]).pluck(:id)

end

search_banker_assignment params

render template: 'cc_banker_assignments/index'

end

How do i do this using rails

网友答案:

Are you trying to clear the form inputs by requesting index page? You can use link_to instead of button_tag to do that, or just javascript. If you really want to pass a variable to the controller, you can bind your button to a jQuery.ajax() call.

分享给朋友:
您可能感兴趣的文章:
随机阅读: