0

I can't understand why this simple routing isn't working right now.

The link below doesn't work: it gives routing error No route matches [DELETE] "/questions"

<%= link_to 'delete', @question, :method => :delete, :action => :destroy %>

rake routes shows

DELETE /questions/:id(.:format)                        questions#destroy

correctly.

Does anyone can find the reason for this error?

Maximus S
  • 10,759
  • 19
  • 75
  • 154

1 Answers1

1

Try

<%= link_to 'delete', question_path(@question), :method => :delete, :confirm => "Are you sure?" %>
Soundar Rathinasamy
  • 6,658
  • 6
  • 29
  • 47
  • Your solution gives, `No route matches {:action=>"show", :controller=>"questions", :id=>#}` and the same problem has happened to me in post http://stackoverflow.com/questions/14451785/simple-routing-in-rails – Maximus S Jan 23 '13 at 09:49
  • 1
    @Maximus S: That would be because your `@question` object is not set up correctly. Please show us how you're setting it up within your controller. – Ryan Bigg Jan 23 '13 at 09:58
  • You can see from the error message that the question_id is nil. You need an id for that route to work. – Marcelo De Polli Jan 23 '13 at 10:01
  • @RyanBigg you were right. I was calling `@question` when I should've called `question` – Maximus S Jan 23 '13 at 10:03