I’m trying to delete the last database record but when I press the link, the page just refreshes and I dont get anything :/
Here’s my controller:
def delete
@todo_items = Todo.last
@todo_items.delete
end
& here’s my view
<h1>Shared Todo App</h1>
<p>All your todos here</p>
<% @todo_items.each do |t| %>
<li><%= t.todo_item %>
<% end %>
<%= link_to 'Delete', todo_item, confirm: 'Are you sure?', method: :delete %>
Any ideas?
First, your action name should be
destroy, notdelete. A link withmethod: :deletewill by default map to an action nameddestroy. See this guide for details.Second, you probably want to redirect somewhere at the end of your
destroyaction. For example,redirect_to root_path, or whatever is appropriate.