First, you need to add a delete link on the index page and provide a delete confirmation that the user confirms the deletion and deletes the data directly.
Modify views
Modify the App/views/posts/index.html.erb as follows:
That adds the
<%= link_to "Delete", post,: Confirm = "Is you sure",:method=>:d elete)
Post is the strength variable to remove: Confirm, confirm whether to delete,: Method of HTTP request, here is the delete request. See [Ruby on Rails] and I learned route map for details.
Modify actionFor the action of the delete request is destroy, modify the Destroy method of the App/controllers/posts_controller.rb file as follows:
def destroy @post = Post.find (Params[:id]) @post. Destroy redirect_to Posts_path,:notice=> "Your post has been deleted " end
Running the serviceWhen you run the service, the Discovery confirmation box does not come out (this issue will be subject to follow), others are normal.
[Ruby on Rails] and I learned to delete data