2017-02-06 1 views
0

Ich habe den folgenden CodeRails PATCH-Methode statt POST

<%= form_for @campaign, url: brands_campaign_path(@campaign), method: :patch, :html => {:multipart => true, :class => 'form-horizontal'} do |f| %> 

, die folgenden

<form class="form-horizontal" id="edit_campaign_25" enctype="multipart/form-data" action="/campaigns/testing" accept-charset="UTF-8" method="post"> 
<input name="utf8" type="hidden" value="&#x2713;" /> 
<input type="hidden" name="_method" value="patch" /> 
<input type="hidden" name="authenticity_token" value="Ybl3G26TZumVbbCew2EmlVxq4Dv2JZx5PAq1Q7nup3vp0GdkT72oIlV==" /> 

Aber auf der Server-Seite erzeugt. Ich habe überprüft, dass die jquery_ujs.js Javascripts auch in den Browser geladen wird.

Rake Routen

brands_campaigns GET /campaigns(.:format)           brands/campaigns#index {:subdomain=>"brands"} 
                 POST /campaigns(.:format)           brands/campaigns#create {:subdomain=>"brands"} 
            new_brands_campaign GET /campaigns/new(.:format)          brands/campaigns#new {:subdomain=>"brands"} 
           edit_brands_campaign GET /campaigns/:id/edit(.:format)        brands/campaigns#edit {:subdomain=>"brands"} 
             brands_campaign GET /campaigns/:id(.:format)          brands/campaigns#show {:subdomain=>"brands"} 
                 PATCH /campaigns/:id(.:format)          brands/campaigns#update {:subdomain=>"brands"} 
                 PUT /campaigns/:id(.:format)          brands/campaigns#update {:subdomain=>"brands"} 
                 DELETE /campaigns/:id(.:format)          brands/campaigns#destroy {:subdomain=>"brands"} 
           brands_campaigns_posts GET /campaigns/:id/posts(.:format)        brands/campaigns#posts {:subdomain=>"brands"} 
          brands_campaigns_details GET /campaigns/:id/details(.:format)        brands/campaigns#details {:subdomain=>"brands"} 
         brands_campaigns_influencers GET /campaigns/:id/influencers(.:format)       brands/campaigns#influencers {:subdomain=>"brands"} 
       brands_campaigns_submit_for_approval GET /campaigns/:id/submit_for_approval(.:format)     brands/campaigns#submit_for_approval {:subdomain=>"brands"} 
        brands_campaigns_pending_to_draft GET /campaigns/:id/pending_to_draft(.:format)     brands/campaigns#pending_to_draft {:subdomain=>"brands"} 
           brands_campaigns_cancel GET /campaigns/:id/cancel(.:format)        brands/campaigns#cancel {:subdomain=>"brands"} 
         brands_campaigns_add_credits GET /campaigns/:id/add_credits(.:format)       brands/campaigns#add_credits {:subdomain=>"brands"} 

logs

ActionController::RoutingError (No route matches [POST] "/campaigns/testing/edit"): actionpack (4.2.5.2) 
lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call' rollbar (2.14.0) 
lib/rollbar/middleware/rails/show_exceptions.rb:22:in `call_with_rollbar' web-console (2.3.0) 
lib/web_console/middleware.rb:20:in `block in call' web-console (2.3.0) 
lib/web_console/middleware.rb:18:in `catch' web-console (2.3.0) 
lib/web_console/middleware.rb:18:in `call' actionpack (4.2.5.2) 
lib/action_dispatch/middleware/show_exceptions.rb:30:in `call' railties (4.2.5.2) 
lib/rails/rack/logger.rb:38:in `call_app' railties (4.2.5.2) 
lib/rails/rack/logger.rb:20:in `block in call' activesupport (4.2.5.2) 
lib/active_support/tagged_logging.rb:68:in `block in tagged' activesupport (4.2.5.2) 
lib/active_support/tagged_logging.rb:26:in `tagged' activesupport (4.2.5.2) 
lib/active_support/tagged_logging.rb:68:in `tagged' railties (4.2.5.2) 
lib/rails/rack/logger.rb:20:in `call' actionpack (4.2.5.2) 
lib/action_dispatch/middleware/request_id.rb:21:in `call' rack (1.6.5) 
lib/rack/methodoverride.rb:22:in `call' rack (1.6.5) 
lib/rack/runtime.rb:18:in `call' activesupport (4.2.5.2) 
lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call' rack (1.6.5) 
lib/rack/lock.rb:17:in `call' actionpack (4.2.5.2) 
lib/action_dispatch/middleware/static.rb:116:in `call' rack (1.6.5) 
lib/rack/sendfile.rb:113:in `call' railties (4.2.5.2) 
lib/rails/engine.rb:518:in `call' railties (4.2.5.2) 
lib/rails/application.rb:165:in `call' rack (1.6.5) 
lib/rack/tempfile_reaper.rb:15:in `call' rack (1.6.5) 
lib/rack/lint.rb:49:in `_call' rack (1.6.5) 
lib/rack/lint.rb:37:in `call' rack (1.6.5) 
lib/rack/showexceptions.rb:24:in `call' rack (1.6.5) 
lib/rack/commonlogger.rb:33:in `call' sinatra (1.4.7) 
lib/sinatra/base.rb:219:in `call' rack (1.6.5) 
lib/rack/chunked.rb:54:in `call' rack (1.6.5) 
lib/rack/content_length.rb:15:in `call' unicorn (5.2.0) 
lib/unicorn/http_server.rb:562:in `process_client' unicorn (5.2.0) 
lib/unicorn/http_server.rb:658:in `worker_loop' unicorn (5.2.0) 
lib/unicorn/http_server.rb:508:in `spawn_missing_workers' unicorn (5.2.0) 
lib/unicorn/http_server.rb:132:in `start' unicorn (5.2.0) 
bin/unicorn:126:in `<top (required)>' 
/usr/local/rvm/gems/ruby-2.3.1/bin/unicorn:23:in `load' 
/usr/local/rvm/gems/ruby-2.3.1/bin/unicorn:23:in `<main>' 
/usr/local/rvm/gems/[email protected]/bin/ruby_executable_hooks:15:in `eval' 
/usr/local/rvm/gems/[email protected]/bin/ruby_executable_hooks:15:in `<main>' 

welchen Weg sollte es getroffen, wie es auf Firefox tut

Started PATCH "/campaigns/testing" for 106.51.30.182 at 2017-02-06 11:18:02 -0500 
+0

können Sie die Ausgabe für './bin/rake Routen im Snippet gezeigt Post | grep -i Kampagne? – Swanand

+0

@Swanand haben es updatd :) –

+0

Was meinst du mit "ich bekomme POST Anfrage"? Wie @Alfie unten zeigt, genau das soll passieren. Meinst du, dass es die 'POST/campaigns (.: Format)' Route statt der 'PATCH/campaigns /: id (.: Format)' Route verschickt, also glaubst du, dass es den versteckten '_method' Wert ignoriert? –

Antwort

3

aus der Dokumentation:

Verfahren zu verwenden, wenn Sie das Formular absenden, in der Regel entweder „get“ oder „post“. Wenn "patch", "put", "delete" oder ein anderes Verb verwendet wird, wird eine versteckte Eingabe mit dem Namen _method hinzugefügt, um das Verb über den Beitrag zu simulieren.

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

wie in Ihrer Frage <input type="hidden" name="_method" value="patch" /> simuliert die patch Methode über post

+0

Wie bereits erwähnt, funktioniert es in Chrome und Safari nicht so wie es sollte. –