I'm trying to create a blog in rails, and I'm having a little trouble. I keep getting the page for my show method each time I try to use my destroy method to test deleting an article from my blog. This is the destroy method:
def destroy
@article = Article.find(params[:id])
@article.destroy
flash[:notice] = "Article has been deleted."
redirect_to articles_path
end
And this is the index file for the home page:
<h1>Listing all articles</h1>
<p>
<%= link_to "Create new artilce", new_article_path %>
</p>
<table>
<tr>
<th>Titile</th>
<th>Text</th>
</tr>
<% @articles.each do |article| %>
<tr>
<td><%= article.title %></td>
<td><%= article.text %></td>
<td><%= link_to 'Edit', edit_article_path(article) %></td>
<td><%= link_to 'Show', article_path(article) %></td>
<td><%= link_to 'Delete', article_path(article), method: :delete, data: {confirm: "Are you sure?"} %></td>
</tr>
<% end %>
</table>
If someone could please tell me where the faulty code is, I would greatly appreciate it.
Aucun commentaire:
Enregistrer un commentaire