2012-11-01 66 views
2

我不明白試圖更新配方沒有路由匹配:動作=>編輯軌道3

這是我的耙路輸出時,爲什麼我收到上述錯誤信息

 recipes GET /recipes(.:format)    recipes#index 
       POST /recipes(.:format)    recipes#create 
    new_recipe GET /recipes/new(.:format)   recipes#new 
    edit_recipe GET /recipes/:id/edit(.:format)  recipes#edit 
     recipe GET /recipes/:id(.:format)   recipes#show 
       PUT /recipes/:id(.:format)   recipes#update 
       DELETE /recipes/:id(.:format)   recipes#destroy 
     root  /        public_pages#index 

我的控制器看起來像這樣

def edit 
    @recipe = Recipe.find(params[:id]) 
end 

def update 
    @recipe = Recipe.find(params[:id]) 

    if @recipe.update_attributes(params[:recipe]) 
    redirect_to recipes_path, :notice => "Successfully updated recipe" 
    else 
    render :action => 'edit' 
    end 
end 

而且我的鏈接編輯的帖子

<%= link_to "Edit Recipe", edit_recipe_path(@recipe) %> 

完整的錯誤時(這艱難時訪問食譜頁面

Routing Error 

No route matches {:action=>"edit", :controller=>"recipes"} 

Try running rake routes for more information on available routes. 

最後我使用的形式,現在我能想到的是,有一個問題,我的形式唯一,雖然我認爲你可以使用新的和編輯相同的表單?儘管我可能是完全錯誤的

任何人有任何想法

+0

添加你的錯誤回溯的前幾行,那麼我們(和你)可以看到錯誤是來自控制器還是來自視圖。 – Thilo

+0

@Thilo,這是你的意思(檢查編輯結束問題) – Richlewis

+0

'沒有路線匹配{:action =>「編輯」,:控制器=>「食譜」}'=>沒有ID,因此也許'@ @當你做'edit_recipe_path(@recipe)'時,recipe'沒有被實例化? –

回答

2

確定,所以它好像我需要這在我看來

<%= link_to "Edit Recipe", edit_recipe_path(r.id) %> 

,這是因爲我經過

<% @recipes.each do |r| %> 
相關問題