Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 321
Toby Avatar asked Feb 06 '14 13:02

Toby


1 Answers

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

like image 112
Alejandro Silva Avatar answered Oct 10 '22 00:10

Alejandro Silva