[英]Rails, change URL for a POST action within a controller
我希望在對控制器內的某個動作進行調用時更改URL。 我目前的情況:
控制器:
class EventController < ApplicationController
def index
if city.blank?
failure
end
...
end
def failure
...
render 'failure'
end
end
路線:
get '/event', to: 'event#index'
post '/event/failure' => 'event#failure'
但是此代碼將url保留為/ events。 預期的結果是/ events / failure
我已查看付款“索引”和“失敗”的信息。 我正在使用Rails〜5.0.0。
要更改URL,您將需要進行重定向,如下所示:
class EventController < ApplicationController
def index
if city.blank?
redirect_to action: 'failure'
end
...
end
def failure
...
render 'failure'
end
end
但是, HTTP / 1.1中給出的POST請求無法重定向
您可能需要考慮更改策略。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.