gpt4 book ai didi

ruby-on-rails - 未定义的方法 'patch' - 路由错误

转载 作者:行者123 更新时间:2023-12-04 06:13:10 24 4
gpt4 key购买 nike

我是 Rails 和 MVC 开发的初学者,需要以下方面的帮助:

我正在做 http://edgeguides.rubyonrails.org/getting_started.html 中的示例

在“5.12 更新帖子”中,我们被要求将以下内容添加到我们的 config/routes.rb 中:

patch "posts/:id" => "posts#update"

如果我这样做并运行 rake routes,我会收到以下错误:

undefined method `patch' for #<ActionDispatch::Routing::Mapper:0x390f078>

当我访问 - http://localhost:3000/posts/1

时出现同样的错误

这是 edit.html.erb 中的行:

<%= form_for :post, url: { action: :update, id: @post.id }, method: :patch do |f| %>

我有 Rails 3.2.1。

环境:

我在 Windows 7 中执行此操作。我通过 railsinstaller.org 安装了 Rails。浏览器 - Chrome、Firefox

最佳答案

patch 仅在 Rails master 分支中可用。

除其他事项外,您需要指向 Gemfile 中的 git 存储库才能在已存在的项目上使用 edge rails。

gem 'rails', :git => 'git://github.com/rails/rails.git'

现在您应该只使用PUT 而不是PATCH。即使 4.0 出来了,PUT 也不会去任何地方。

关于ruby-on-rails - 未定义的方法 'patch' - 路由错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14658830/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com