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?

andrzej541
  • 919
  • 1
  • 9
  • 21

1 Answers1

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.

Dmitry Barskov
  • 1,200
  • 8
  • 14
  • 1
    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. https://stackoverflow.com/questions/6057972/how-do-i-url-escape-a-string-in-rails – sam Nov 30 '20 at 12:51