Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails "action" params key conflict

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?

like image 470
Jeremy Blalock Avatar asked May 13 '15 06:05

Jeremy Blalock


2 Answers

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

 request.POST
like image 68
apneadiving Avatar answered Nov 19 '22 22:11

apneadiving


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
like image 39
Lane Avatar answered Nov 19 '22 22:11

Lane