I get a JSON array from another app which looks like this (from the log)
Parameters: {"auth_token"=>[{"auth_token"=>"d11D1E3v7pKkLW4wDj8ohgtf"}]}
This array will be bigger (that's the reason for using arrays) but I'm only testing if I can get the content from it. This is my function:
def valid_request_array
data = ActiveSupport::JSON.decode(params)[:auth_token]
Usuario.find_by_auth_token(data[0]['auth_token']).present?
end
I get the following error:
TypeError (no implicit conversion of ActionController::Parameters into String): app/controllers/api/actas_controller.rb:35:in `valid_request_array'
Line 35 is data = ActiveSupport::JSON.decode(params)[:auth_token]
I have rails 4.2 and also tried with JSON.parse(params) and JSON.parse(params[:auth_token]) but it doesn't works. There's a similar question here JSON Array parsing in ROR but I need to read the value in order to authenticate that request. Any help is appreciated