如何在控制器中不使用 Rails 动作参数 [英] How to not use Rails action parameter in controller
问题描述
我正在 Rails 服务器中为 Shipworks 实现第三方 API,而 Shipworks 客户端应用程序正在发布具有 Shipworks 特定语义的 action
参数.
I am implementing a third party API for Shipworks in a Rails server and the Shipworks client app is posting an action
param with Shipworks specific semantics.
然而,Rails 路由逻辑将这个参数覆盖为控制器方法的名称.
However the Rails routing logic overwrites this param to be the name of the controller method.
是否有我可以编写的自定义路由来获取该操作参数的值,而不会将其覆盖为我的控制器方法的名称?
Is there a custom route I could write to get the value of that action param without it being overwritten to be the name of my controller method?
推荐答案
我今天陷入了这个陷阱,并在控制器方法中提出了这个解决方案.这是 Rails 4.1:
I fell into this trap today and came with this solution in controller method. It's Rails 4.1:
if request.method == "POST"
action = request.request_parameters['action']
else
action = request.query_parameters['action']
end
这篇关于如何在控制器中不使用 Rails 动作参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!