我試圖通過的link_to通過以下方式發送POST請求:的Rails的link_to發送POST,當您使用方法GET請求:後
link_to 'go to transition', transition_diagnosis_path, method: :post
。
我的DiagnosisController
的行動transition
,但是當我點擊鏈接時,這會發送兩個請求,POST和GET。第一個請求成功執行,但最後一個請求將未知參數發送到show
操作,因此會返回錯誤。
Started POST "/diagnosis/transition" for 127.0.0.1 at 2017-02-08 17:45:32 -0200
Processing by DiagnosisController#transition as HTML
Parameters: {"authenticity_token"=>"XXXXXXXXXXXXX"}
Redirected to http://localhost:3000/analysis
Completed 302 Found in 1126ms (ActiveRecord: 128.0ms)
Started GET "/diagnosis/transition" for 127.0.0.1 at 2017-02-08 17:45:33 -0200
Processing by DiagnosisController#show as HTML
Parameters: {"id"=>"transition"}
Completed 500 Internal Server Error in 975ms (ActiveRecord: 24.8ms)
有誰知道我該怎麼辦?提前致謝。
UPDATE:
當我試圖做到這一點的正常工作
link_to transition_diagnosis_path, method: :post do
button_tag 'go to transition'
end
嘗試添加'遠程:TRUE'選項,看的出它行爲 –
@DamianSimonPeter add'remote:true'保持相同的行爲。點擊鏈接繼續發送兩個請求。 –