Undefined method 'patch' - routing error
I am starting to develop Rails and MVC and need help below:
I am doing an example at http://edgeguides.rubyonrails.org/getting_started.html
In "5.12 Updating Messages" we are asked to add the following to our config / routes.rb:
patch "posts/:id" => "posts#update"
If I do this and run rake routes
, I get the following error:
undefined method `patch' for #<ActionDispatch::Routing::Mapper:0x390f078>
I am getting the same error when I go - http://localhost:3000/posts/1
This is the line in the edit.html.erb file:
<%= form_for :post, url: { action: :update, id: @post.id }, method: :patch do |f| %>
I have Rails 3.2.1.
Environment:
I am doing this on Windows 7. I installed Rails via railsinstaller.org. Browsers - Chrome, Firefox
patch
only available in the Rails branch master
.
- Here is a related pull request: https://github.com/rails/rails/issues/348
- Here is a blog article explaining the reasoning: http://weblog.rubyonrails.org/2012/2/25/edge-rails-patch-is-the-new-primary-http-method-for-updates/
- Here's another great summary: http://blog.remarkablelabs.com/2012/12/http-patch-verb-rails-4-countdown-to-2013
Among other things, you need to point to the git repo in Gemfile
order to use edge rails in an existing project.
gem 'rails', :git => 'git://github.com/rails/rails.git'
You should now use PUT
instead patch
. Even when 4.0 comes out, it's PUT
not going anywhere.
fwiw, I kept the HTTP PATCH verb working for Rails 3.2 https://gist.github.com/bf4/8940203