3

我是 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

4

2 回答 2

3

patch仅在 Railsmaster分支中可用。

除其他外,您需要指向您的 git 存储库,Gemfile以便在现有项目上使用边缘导轨。

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

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

于 2013-02-02T05:18:16.113 回答
1

fwiw,我向后移植了 Rails 3.2 的 HTTP PATCH 动词工作https://gist.github.com/bf4/8940203

于 2014-02-11T19:11:14.687 回答