Rails “action” params key conflict

我们两清 提交于 2019-12-12 10:42:23

问题


I am building a RESTful Rails service with various CRUD endpoints. On one of the Create endpoints, the data I am passing in includes:

...
action: "action_name"
...

The problem I am having is that params[:action] contains "create", not the actual value of the action parameter I'm passing in. This, I assume, is because params[:action] is being populated by Rails automatically.

Is there another way to access this key I am passing in? Am I doing something blatantly stupid?


回答1:


Its awkward to use this, but if ever its required, you can get the info using:

 request.POST



回答2:


Yes, you can. According to How to not use Rails action parameter in controller , you can get it by:

if request.method == "POST"
  action = request.request_parameters['action']
else
  action = request.query_parameters['action']
end


来源:https://stackoverflow.com/questions/30207671/rails-action-params-key-conflict

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!