5

我有一个 Rails 应用程序,在表格中列出了潜在客户。在其中一个列中,我在下拉菜单中显示潜在客户的状态。我想在更改下拉列表中选择的值时启用更改潜在客户的此状态。

这是我尝试过的:

在表格单元格中显示表单的代码:

      <% @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>

我在潜在客户控制器中的 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

我也希望提交是 Ajax 风格而不刷新。

4

1 回答 1

4

设置表单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 %>
于 2013-04-20T10:32:16.210 回答