TheIrishGuy
TheIrishGuy

Reputation: 2573

No routes match error

Not sure why I'm getting

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

in a link_to in one of my partials

relevant routes.rb

  resources :documents, only: [:create, :destroy, :edit, :update] do
    post 'sort' => 'documents#sort', on: :collection
  end

I recently just added the edit and update actions and thus my current issues rake routes =

  sort_documents POST   /documents/sort(.:format)      documents#sort
       documents POST   /documents(.:format)           documents#create
   edit_document GET    /documents/:id/edit(.:format)  documents#edit
        document PUT    /documents/:id(.:format)       documents#update
                 DELETE /documents/:id(.:format)       documents#destroy

The partial with the problem route is just

 <%= document.title %>
 <%= document.position %>
 <%= link_to 'link_to_test', edit_document_path %>
 <%= link_to 'Delete', document, method: :delete, remote: true %>

my documents_controller.rb has edit defined

def edit
    @document = current_user.documents.find(params[:id])
end

Upvotes: 0

Views: 96

Answers (1)

Mik
Mik

Reputation: 4187

The error occurs because you forgot to specify the object or its id in the edit_document_path. Try this:

<%= link_to 'link_to_test', edit_document_path(document) %>

Upvotes: 1

Related Questions