Home Rails not giving a destroy_path for resource
Reply: 2

Rails not giving a destroy_path for resource

blue Published in 2018-01-12 23:14:59Z

using Rails 5.1.4 & ruby 2.4.1

Wondering why Rails would not give a destroy_visitor_path for DELETE request. Any info would be greatly appreciated. Thank you!


Rails.application.routes.draw do
  root :to => 'contents#index'

  resources :contents
  resources :visitors


            visitors GET    /visitors(.:format)          visitors#index
                     POST   /visitors(.:format)          visitors#create
         new_visitor GET    /visitors/new(.:format)      visitors#new
        edit_visitor GET    /visitors/:id/edit(.:format) visitors#edit
             visitor GET    /visitors/:id(.:format)      visitors#show
                     PATCH  /visitors/:id(.:format)      visitors#update
                     PUT    /visitors/:id(.:format)      visitors#update
                     DELETE /visitors/:id(.:format)      visitors#destroy
Josh Brody
Josh Brody Reply to 2018-01-12 23:21:03Z

Same reason why there's no update_visitor_path — it's a singular resource that simply responds to a different HTTP verb.

In your view, you'd link_to "Delete", visitor_path, method: :delete

I can't comment on the philosophy behind the design decision, or any of the arguments about whatever spec it's designed to because that's for people who are smarter than I am.

More info on the Rails routing guide: http://guides.rubyonrails.org/routing.html

T.Kul Reply to 2018-01-12 23:28:37Z

There are many incidents to delete It's let you set your own routes: For example you want to logout after delete (usually in sessions)

get '/logout' => 'sessions#destroy', :as => 'logout'
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.407433 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO