I am getting started with Ruby and implementing simple blog from their official materials.
I finish the app, but have an issue with destroying action. Here is the form
<h1>Listing Articles</h1>
<%= link_to 'New article', new_article_path %>
<% if !@articles.nil? %>
<table>
<tr>
<th>Title</th>
<th>Text</th>
<th colspan="3"></th>
</tr>
<% @articles.each do |article| %>
<tr>
<td><%= article.title %></td>
<td><%= article.text %></td>
<td><%= link_to 'Show', article_path(article) %></td>
<td><%= link_to 'Edit', edit_article_path(article) %></td>
<td><%= link_to 'Destroy', article_path(article),
method: :delete,
data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</table>
<% else %>
<p> no avaiable articles </p>
<% end %>
And that is available routes
Prefix Verb URI Pattern Controller#Action
welcome_index GET /welcome/index(.:format) welcome#index
root GET / welcome#index
article_comments GET /articles/:article_id/comments(.:format) comments#index
POST /articles/:article_id/comments(.:format) comments#create
article_comment GET /articles/:article_id/comments/:id(.:format) comments#show
PATCH /articles/:article_id/comments/:id(.:format) comments#update
PUT /articles/:article_id/comments/:id(.:format) comments#update
DELETE /articles/:article_id/comments/:id(.:format) comments#destroy
articles GET /articles(.:format) articles#index
POST /articles(.:format) articles#create
new_article GET /articles/new(.:format) articles#new
edit_article GET /articles/:id/edit(.:format) articles#edit
article GET /articles/:id(.:format) articles#show
PATCH /articles/:id(.:format) articles#update
PUT /articles/:id(.:format) articles#update
DELETE /articles/:id(.:format) articles#destroy
You may noticed delete
method on form link and DELETE
request is mapped on articles#destroy
action. However on the click on this link a GET
call instead of DELETE
is invoked (the same URI pattern) and I have not found yet the root cause.
The routing by itself is below
Rails.application.routes.draw do
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
get 'welcome/index'
root 'welcome#index'
post '/articles/:id', to: 'articles#update'
resources :articles, only: [:new, :edit, :index, :create, :show, :update, :destroy] do
resources :comments
end
end
I successed with defining alias for explicitly exposed route, but besides introducing new issues it is not uses platform native way resources :articles
Could you help with understanding\finding the cause of this issue?