[英]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.