Ruby on Rails Friday, August 7, 2015

Hi Everyone,

In one of my controller actions, I am using

data_sent = ActiveSupport::JSON.decode(request.body.read)

to get the JSON object sent to this controller via request that has the object/payload inside the body. I am using curl to send/test this, as follows:

curl -X POST --header "Content-Type: application/json" --header "Accept: application/json" - -d "{\"foo\": \"bar\"}" "http://localhost:3000/foo"

The result is that I get in data_sent a Hash like this: {foo: "bar"}, which seems to be correct.

The question here is whether the way I get the data on controller is the recommended way to do it, or whether there is other more Rails/better way to do it.

Thanks in advance
Panayotis

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/57f6fa3e-0d61-449f-8c22-f4031997bd94%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment