[英]Rails, change URL for a POST action within a controller
I want the URL to be changed when a call to an action within the controller is made. 我希望在对控制器内的某个动作进行调用时更改URL。 My current scenario:
我目前的情况:
Controller: 控制器:
class EventController < ApplicationController
def index
if city.blank?
failure
end
...
end
def failure
...
render 'failure'
end
end
Routes: 路线:
get '/event', to: 'event#index'
post '/event/failure' => 'event#failure'
But this code keeps the url as /events. 但是此代码将url保留为/ events。 The desired result is /events/failure
预期的结果是/ events / failure
I've views for payment 'index' and 'failure'. 我已查看付款“索引”和“失败”的信息。 I'm using rails ~ 5.0.0.
我正在使用Rails〜5.0.0。
For the URL to change you will want to do a redirect, something like this : 要更改URL,您将需要进行重定向,如下所示:
class EventController < ApplicationController
def index
if city.blank?
redirect_to action: 'failure'
end
...
end
def failure
...
render 'failure'
end
end
But, redirection is not possible for POST requests as given in HTTP/1.1 但是, HTTP / 1.1中给出的POST请求无法重定向
You might want to consider changing your strategy. 您可能需要考虑更改策略。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.