---
title: "《三》Couldn't find Product with ID=list  "
author: "xiayw"
date: "2010-07-17T15:38:22Z"
tags: []
categories: ["编程语言"]
slug: "couldn-t-find-product-with-id-list"
draft: false
lastmod: "2010-07-17T15:38:22Z"
id: 715063
url: "https://xiayw.iteye.com/blog/715063"
---

老郁闷了 以前很简单的功能现在不成了



后来从网上找到 ：




原来它不认 list 那就改成 index 吧， 现在还是不明白为什么不能用 list 了
为什么 rake routes 里没有 这个


说说 edit 功能

```java

<% form_tag url_for({ :id => @product,:action=>"update"}) ,:method => :put  do %>

  <%= render :partial => 'form' %>
  <%= submit_tag "Edit" ,:name => nil %>
<% end %>


```

这里 :method => :put 很重要，如果不写 你就等错吧 特别奇妙的是
它会吧 :action=>"update" 给吞了

所以 delete 也得改  :method => :delete 
否则 你怎么都没有办法从 list 上删除  记录
其实因为它没有找到 规则 不给 :method 默认是 post 
它找不到 就 会 去掉 action 
结果  url 就变成 localhost:3000/products/：id
还会报错




摘录 挂于 routes 的 内容：

> 
> 自己加的路由一定要 加在  map.resource 前面
> 因为
> 单资源rest风格路由规则： map.resource
> 
>    我们定义这样一个规则： map.resource :account
> 
>    它会帮我们定义怎样的一个路由规则呢？ 答案是一个遵循rest风格的路由规则，非常完美。
> 
> ruby代码
> 
>    1. # maps these actions in the accounts controller:  
>    2. class accountscontroller < actioncontroller::base  
>    3.     # get new_account_url  
>    4.      def new  
>    5.        # return an html form for describing the new account  
>    6.     end  
>    7.     
>    8.     # post account_url  
>    9.     def create  
>   10.       # create an account  
>   11.     end  
>   12.    
>   13.     # get account_url  
>   14.     def show  
>   15.       # find and return the account  
>   16.     end  
>   17.     
>   18.    # get edit_account_url  
>   19.     def edit  
>   20.       # return an html form for editing the account  
>   21.     end  
>   22.    
>   23.     # put account_url  
>   24.     def update  
>   25.       # find and update the account  
>   26.     end  
>   27.     
>   28.    # delete account_url  
>   29.     def destroy  
>   30.       # delete the account  
>   31.     end  
>   32.  end 
> 
> 
> 
> 所以 原来我 list 功能不能用就是 我自己加的路由 加在 它后面被它先捕获  url先分析了， 我的公则就没有用了， 改成下面的情况就能正常工作了
> [list]
> [
> map.connect 'products/list', :controller => 'products', :action => 'list'
>   map.resources :products
> 
> ]
> [/list]  
>