user984621
user984621

Reputation: 48521

Link for destroy returns "undefined method"

I have the*Topics* controller and in the view/topics/index.html.erb the link for destroying item:

<%= link_to 'Destroy',topic, confirm: 'Are you sure?', method: :delete %>

I tried also

<%= link_to 'Destroy', topic_path(topic), confirm: 'Are you sure?', method: :delete %>

but both returns

undefined method topic_path for Class:0x00000105056a80>: 0x00000105047328>

in routes.rb is following:

  namespace :admin do
    ...
    resources :topics
  end

Where could be the problem and how to in the easily way to solve it? I was checking the other generated controllers/views by CRUD, and the setup is always the same and in all other controllers it's working well, just in this one I am getting over and over again this error.

Upvotes: 0

Views: 769

Answers (1)

megas
megas

Reputation: 21791

Try this:

<%= link_to 'Destroy', admin_topic_path(topic), 
                                    confirm: 'Are you sure?', method: :delete %>

To make sure run command rake routes, in the result you should see your route.

Upvotes: 3

Related Questions