[英]Submit Rails from on change of selected value in dropdown form
I have a Rails app with listing of leads in a table. 我有一个Rails应用程序,其中包含表格中的潜在客户列表。 In one of the collumns I display status of a lead in a drop down menu.
在其中一个列中,我在下拉菜单中显示潜在客户的状态。 I want to enable changing this status of the lead on changing the value selected in the drop down.
我想在更改下拉列表中选择的值时启用更改潜在客户的此状态。
This is what I tried: 这是我试过的:
The code to display 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 leads controller: 我在引导控制器中的update_lead_status方法:
#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
Also I want the submission to be Ajax style without refreshing. 此外,我希望提交是Ajax风格而不刷新。
Set form id and then submit form 设置表单ID,然后提交表单
<%= 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 %>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.