【问题标题】:Getting no route matches error despite having "resources" in my config/routes.rb file尽管我的 config/routes.rb 文件中有“资源”,但没有路由匹配错误
【发布时间】:2016-09-24 22:55:21
【问题描述】:

我正在使用 Rails 4.2.3,当我访问我的查看包含以下链接的视图

<%= link_to 'Delete',url_for(controller: 'my_objects', action: :delete,id: my_object_time.my_object.id),method: :delete, data: {confirm: "Are you sure you want to delete this data?"} %>

但是,在我的 routes/config.rb 文件中,我已经包含了

resources :my_objects

我什至在我的 my_objects_controller.rb 文件中有这个方法……

  def delete
    my_object.find(params[:id]).destroy
    format.html { redirect_to controller: "users", action: "index", notice: 'Delete successful.' }
  end

所以我不确定它为什么会分崩离析。任何帮助表示赞赏, - 戴夫

【问题讨论】:

  • delete 是正确的 HTTP 动词。不过,Rails 控制器操作需要调用 destroy

标签: ruby-on-rails ruby-on-rails-4 controller routes


【解决方案1】:

试试这个:

<%= link_to 'Delete',url_for(controller: 'my_objects', action: :destroy,id: my_object_time.my_object.id),method: :delete, data: {confirm: "Are you sure you want to delete this data?"} %>

<%= link_to 'Delete',  my_object_time.my_object.id,  method: :delete, data: { confirm: 'Are you sure?' } %>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-23
    • 1970-01-01
    相关资源
    最近更新 更多