Search code examples
ruby-on-railscrudrestful-urlrestful-architecture

Rails CRUD - Destroy path always routes to the User show page


My view is the users show page

<%= link_to 'Cancel?', {:url => schedule_path,
                        :id => current_user.schedules[0].id,
                        :confirm => "are you sure?",
                        :method => :delete} %>

Associations

has_many :schedules
belongs_to :user

routes.rb

resources :schedules 
resources :users  

I don't match anything in routes.rb. The parameters in the stack trace show id => 93, which is what I want as I'm trying to destroy the schedule with id 93. But it's routing to the show action of the user's controller when I want the destroy action of the schedule's controller. Thanks for any help.


Solution

  • Try to link_to 'Cancel?', schedule_path(current_user.schedules[0]), :confirm => "are you sure?", :method => :delete