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

大城市里の小女人 提交于 2019-12-12 02:45:16

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/8065717/rails-crud-destroy-path-always-routes-to-the-user-show-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!