1

I begin to create a rails API for react. I pass a GET request with params inside url like this:

api/dashboard/price?"foo"="bar"

But my rails app by default cannot decode it properly and on backend side. My params object looks this way:

<ActionController::Parameters {"\"foo\""=>"\"bar\"", "controller"=>"api/dashboards", "action"=>"price"} permitted: false>

Furthermore I cannot access any of those keys e.g:

params[:foo]

returns nil

How can I get rid of those slashes and decode url params proper way?

2
  • "I pass a GET request with params inside url like this" - there's your problem. Don't pass params like this (with quotes). Commented Nov 30, 2020 at 12:27
  • Have you tried to make a request without double quotes? api/dashboard/price?foo=bar Commented Nov 30, 2020 at 12:32

1 Answer 1

2

If you want to pass url params with quotes "foo" then you should also access them with quotes like this: params['"foo"'].

But if you want to make params[:foo] work then just pass them without any quotes. api/dashboard/price?foo=bar.

Sign up to request clarification or add additional context in comments.

1 Comment

Agree with Dmitry, but don't do the first option. Just pass api/dashboard/price?foo=bar. It's much cleaner. If you need bar to be multiple words just URL escape it. stackoverflow.com/questions/6057972/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.