2011-12-28 2 views
1

경로 이름 문제가 간단합니다. 나는 가지고있다 :라우팅이라는 간단한 레일 문제가 발생했습니다.

#Controller: 

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

#Routes.rb: 

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

나는 얻는 응답은 Couldn't find Thing without an ID이다. I가 컨트롤러를 변경하는 경우 :

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

은 그 때 나는 Couldn't find Thing with ID=thing를 얻을. 내가 뭘 놓치고 있니?

+2

실제로 명명 된 경로를 사용하고 있지 않습니다. 가장 일반적인 경로는'resources : things'에 의해 생성되고'things_url'과 다른 path/url 헬퍼를 사용할 수있게 해주는 경로입니다. –

답변

5
@thing = Thing.find_by_name(params[:name]) 
관련 문제