Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialKarrtik Iyer
3,738 PointsInstead of method:delete in erb can we use delete_path or destory_path?
Instead of below code:
<%= link_to 'Delete', @page, method: :delete %>
can we also do something like below?
<%= link_to 'Delete', page_delete_path(@page)%>
And in routes file we set up the #destroy with this path
delete '/pages/:id', to:'pages#destroy', as:'page_delete'
1 Answer
Jay McGavren
Treehouse TeacherThis line in your routes.rb
:
delete '/pages/:id', to:'pages#destroy', as:'page_delete'
...sets up a route that will only be triggered by delete requests, which means you need that method: :delete
in your ERB. You could make this work by creating a get
route (with a totally separate path like "/pages/:id/delete"
, not "/pages/:id"
), but that breaks convention and I would strongly recommend against it.