Nona
Nona

Reputation: 5472

How to pass nested arrays over http via HTTParty in Rails 4 application

I call a controller action "passit" of Rails app A and want to pass an array b to an api update call via an HTTP request using the HTTParty gem patch method:

def passit
  b=[[1,2,3],[4,5,6]]
  params["a"] = b.to_json
  id=5
  @options = {query: params}
  @response = HTTParty.patch("someapi.com/#{id}", @options)
end

The only way I have found to pass b so far so that a value other than nil gets passed to the API is to stringify it via to_json.

Is the only way to pass a nested array via a patch/put/some kind of update request over http is to "stringify" the parameter via JSON or converting it to a string?

Upvotes: 0

Views: 381

Answers (1)

ReggieB
ReggieB

Reputation: 8257

Have a look at Marshal. That allows you to convert objects into byte streams that you can then transfer more easily.

Upvotes: 1

Related Questions