I think the resources method is indispensable for RESTful development ~ (I just want to say)
I learned resources because I thought it was difficult to understand what kind of path was actually taken without seeing the actual contents.
This time I will focus on the destroy that I happen to be implementing! Please implement the delete button!
routes.rb
Rails.application.routes.draw do
resources :tweets :only => [:destroy]
end
Normally, I don't think it's easy to set only destroy,
In the terminal, run rake routes
to see the routes!
tweets DELETE /tweets/:id(.:format) tweets#destroy
The path that can be set with this is as follows
URL | action | HTTP method | Named path(_path) | Named path(_url) | Corresponding path |
---|---|---|---|---|---|
/tweets/:id(.:format) | destroy | DELETE | tweet_path(id) | tweet_url(id) | /tweets/:id |
<%= link_to "Delete", tweet_path(○○ variable name.id), method: :delete , data: { confirm: "Deleteしますか?"} %>
I think the variable name depends on the time and the case! (In short, it's OK if you can get the id of the record you want to delete)
that's all~
Recommended Posts