我该如何传入ID?PUT-form更新行,但我找不到id。它在哪里?
错误:
Couldn't find Product without an ID
形式:
<% form_for :product, @product, :url => { :action => :update } do |f| %>
<%= f.error_messages %>
<p>
<%= f.label :names %><br />
<%= f.text_field :names %>
</p>
<p>
<%= f.submit 'Update' %>
</p>
<% end %>
控制器(用于/产品/编辑/ 1视图):
def edit
@product = Product.find(params[:id])
end
控制器(改变分贝):
def update
@product = Product.find(params[:id])
respond_to do |format|
if @product.update_attributes(params[:product])
format.html { redirect_to(@product, :notice => 'Product was successfully updated.') }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @product.errors, :status => :unprocessable_entity }
end
end
end
没有工作,不幸的是 – montooner 2010-06-16 22:20:42
这导致t o“没有任何操作回应1.操作:创建,编辑,索引,新建,显示和更新”问题“ – montooner 2010-06-16 22:30:10
尝试在您的URL散列中添加:id => @ product.id。 此外,你是否在你的路线中使用map.resources? – Maz 2010-06-16 22:32:50