2011-12-28 72 views
1

我被這個簡單的命名路由問題困住了。我有:簡單導軌命名路由問題

#Controller: 

    def show 
    @thing = Thing.find(params[:id]) 
    end 

#Routes.rb: 

    match '/:name' => 'things#show' 

我得到的響應是Couldn't find Thing without an ID。如果我將控制器更改爲:

@thing = Thing.find(params[:name]) 

然後我得到Couldn't find Thing with ID=thing。我錯過了什麼?

+2

事實上,你根本沒有使用命名路線。最常見的命名路由是由'resources:things'生成的路由,並允許您使用'things_url'和其他路徑/ url助手。 – 2011-12-28 09:29:46

回答

5
@thing = Thing.find_by_name(params[:name])