Richlewis
Richlewis

Reputation: 15374

No route matches :action => edit rails 3

I don’t understand why I am getting the above error message when trying to update a recipe

This is my output of rake routes

      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

My controller looks like this

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

And my link to edit the post

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

the full error is (this is when trying to access the recipes page

Routing Error

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

Try running rake routes for more information on available routes. 

and finally the form i am using, now the only thing I can think of is that there is an issue with my form, though i thought that you could use the same form for new and edit? though i could be totally wrong

Anyone have any ideas

Upvotes: 2

Views: 2161

Answers (1)

Richlewis
Richlewis

Reputation: 15374

ok so it seems as if i needed this in my view

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

this was because i was passing

 <% @recipes.each do |r| %>

Upvotes: 2

Related Questions