Send Rails from changing the selected value in the drop-down list

I have a Rails application with a list of potential customers in a table. In one of the columns, I show the status of the output in the drop-down menu. I want to enable the change of this state of the master when changing the value selected in the drop-down list.

This is what I tried:

Code for displaying the form in a table cell:

<% @leads.each do |lead| %> <tr> <td><%= lead.id %></td> <td><%= form_for(lead,:url => 'update_lead_status') do |f| %> <div class="field"> <%= f.select :status, ["to_call","called","confirmed","lite"], :selected => lead.status, onchange: "this.form.submit();" %> </div> <% end %> </td> 

my update_lead_status method in the output controller:

 #PUT def update_lead_status @lead = Lead.find(params[:id]) respond_to do |format| # format.js if @lead.update_attributes(params[:lead]) format.html { redirect_to leads_url, notice: 'Lead was successfully updated.' } format.json { head :no_content } else format.html { render action: "edit" } format.json { render json: @lead.errors, status: :unprocessable_entity } end end end 

I also want the view to be an Ajax style without updating.

+4
source share
1 answer

Set the form id and then submit the form

 <%= form_for(lead,:url => 'update_lead_status',:html=>{:id=>'lead_form'}) do |f| %> <%= f.select :status, ["to_call","called","confirmed","lite"], :selected => lead.status, onchange: "$('#lead_form').submit();" %> <% end %> 
+4
source

All Articles