javascript - Submit Rails from on change of selected value in dropdown form -
i have rails app listing of leads in table. in 1 of collumns display status of lead in drop down menu. want enable changing status of lead on changing value selected in drop down.
this tried:
the code display form in table cell:
<% @leads.each |lead| %> <tr> <td><%= lead.id %></td> <td><%= form_for(lead,:url => 'update_lead_status') |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 leads controller:
#put def update_lead_status @lead = lead.find(params[:id]) respond_to |format| # format.js if @lead.update_attributes(params[:lead]) format.html { redirect_to leads_url, notice: 'lead updated.' } format.json { head :no_content } else format.html { render action: "edit" } format.json { render json: @lead.errors, status: :unprocessable_entity } end end end
also want submission ajax style without refreshing.
set form id , submit form
<%= form_for(lead,:url => 'update_lead_status',:html=>{:id=>'lead_form'}) |f| %> <%= f.select :status, ["to_call","called","confirmed","lite"], :selected => lead.status, onchange: "$('#lead_form').submit();" %> <% end %>
Comments
Post a Comment