2012-11-01 135 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| %> 
相关问题