我在一个html表中嵌入了一个rails表单作为一个简单的下拉菜单。我还以这样的方式实现了表单,即只要下拉菜单中有更改,就会提交表单。但我收到了一个路由错误,我正试图解决。
<td>
<%= form_for(lead, :action => 'update_lead_status', :html => {:id => 'lead_form'}, :remote => true) do |f| %>
<%= f.select(:status, ["to_call","called","confirmed","lite"], {:selected => lead.status}, :onchange => "$('#lead_form').submit();") %>
<% end %>
</td>
get 'leads/:id/edit_lead_status' => "leads#edit_lead_status"
put 'leads/:id/update_lead_status'=> "leads#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
此表中的嵌入表单位于/ leads网址,我尝试重定向成功更新。
ActionController::RoutingError (No route matches [PUT] "/leads/130"):
status是我的潜在客户模型中的可访问属性。
请告诉我哪里出错了?
更新
所以我尝试了sevenseacat的答案,它调用了我的update_lead_status,但参数错误。我的桌子是这样的:
<% @leads.each do |lead| %>
<tr>
<td><%= lead.id %></td>
<td><%= lead.prefix %></td>
<td><%= lead.name %></td>
<td><%= lead.mobile %></td>
<td><%= lead.phone %></td>
<td><%= lead.category %></td>
<td><%= lead.area %></td>
<td><%= lead.city %></td>
<td><%= lead.updated_at %></td>
<td><%= lead.is_valid %></td>
<td><%= lead.vendor_status %></td>
<td><%= lead.call_tries %></td>
<td>
<%= form_for(lead, url: update_lead_status_path(lead.id), :html => {:id => 'lead_form'}, :remote => true) do |f| %>
<%= f.select(:status, ["to_call","called","confirmed","lite"], {:selected => lead.status}, :onchange => "$('#lead_form').submit();") %>
<% end %>
</td>
<td><%= lead.remarks %><%= link_to lead.remarks, :controller => "leads", :action => "edit_lead_remarks", :id => lead, :remote => true %>
</td>
</tr>
<% end %>
这里对于表中的每一行,它将id作为表中第一个引导的id。
答案 0 :(得分:0)
在routes.rb文件中添加以下代码行后尝试。
resources :leads
答案 1 :(得分:0)
您没有正确指定表单的操作网址 - 例如form_for(lead, url: update_lead_status_path(lead))
(假设您的routes.rb中有named your route,例如as: :update_lead_status
)。