Toby
Toby

Reputation: 8792

Rails 4 not using form method PATCH, defaulting to POST

I have the following line which generates a form tag;

<%= form_for :stream, url: stream_path(@stream), method: :patch do |f| %>  

It generates the following;

<form method="post" action="/streams/52b02d267e3be39d3da5aa609f1049d7" accept-charset="UTF-8">

If I change it to :put it still has it has post but if I write method: :get it will change it to get

Does anyone have any idea why it would be doing this and what I can do to prevent it?

Here is the output from rake routes;

    Prefix Verb   URI Pattern                 Controller#Action
    streams GET   /streams(.:format)          streams#index
           POST   /streams(.:format)          streams#create
 new_stream GET   /streams/new(.:format)      streams#new
edit_stream GET   /streams/:id/edit(.:format) streams#edit
     stream GET   /streams/:id(.:format)      streams#show
          PATCH   /streams/:id(.:format)      streams#update
            PUT   /streams/:id(.:format)      streams#update
         DELETE   /streams/:id(.:format)      streams#destroy

The background is this is a simple edit form, all I want it to do is his the update method of the controller.

Follow up

In my layout file I am bringing in csrf_meta_tags and my javascript_include_tag links to a file called "stream" which has the following

//= require jquery
//= require jquery_ujs

Upvotes: 11

Views: 11911

Answers (2)

Alejandro Silva
Alejandro Silva

Reputation: 9118

method: (:get|:post|:patch|:put|:delete)

from the documentation:

"in the options hash. If the verb is not GET or POST, which are natively supported by HTML forms, the form will be set to POST and a hidden input called _method will carry the intended verb for the server to interpret."

source: http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html

Upvotes: 14

Arun
Arun

Reputation: 1528

is //= require jquery_ujs in your application.js?

also make sure

<%= javascript_include_tag "application"%>
<%= csrf_meta_tag %>

are present in your layout file.

Upvotes: 0

Related Questions