RailsJSONAPIサーバーへのPOSTリクエストは次のようになります。
POST /api/posts.json HTTP/1.1
Accepts: application/json
X-API-KEY: 7d867d16a5e25337b6d7857965f812bee73b76ac
Content-Length: 288
Content-Type: multipart/form-data; boundary=syoYQUQsGwI2XqShQimFdv2QSe-_GYbjVx40T1kS
Host: 10.0.2.2:3000
Connection: Keep-Alive
User-Agent: Apache-HttpClient/UNAVAILABLE (java 1.4)
--syoYQUQsGwI2XqShQimFdv2QSe-_GYbjVx40T1kS
Content-Disposition: form-data; name="DATA"
Content-Type: application/json; charset=UTF-8
Content-Transfer-Encoding: 8bit
{"tags":["dffdff"],"location_id":3,"post":{"content":"test #dffdff"}}
--syoYQUQsGwI2XqShQimFdv2QSe-_GYbjVx40T1kS--
JSONパラメーターにアクセスするにはどうすればよいですか?
ログにparams[:DATA]を書き込むと、属性は表示されますが、ネストされているものはすべて空です(params [:DATA] [:post]やparams [:DATA] [:tags]など)。
アップデート:
私がやろうとしているとき
Rails.logger.debug(params[:DATA])
私は得る
{"tags":["dffdff"],"location_id":3,"post":{"content":"test #dffdff"}}
でもやってみると
Rails.logger.debug(params[:DATA][:post])
私は得る
TypeError (can't convert Symbol into Integer):
app/controllers/api/posts_controller.rb:19:in `[]'
app/controllers/api/posts_controller.rb:19:in `create'