Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8021195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:54:42+00:00 2026-06-04T21:54:42+00:00

I have a post request to a Rails JSON API server that looks like

  • 0

I have a post request to a Rails JSON API server that looks like that:

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--

how do I access the JSON params ?

if I write params[:DATA] to log I see the attributes, but everything nested is empty (such as params[:DATA][:post] or params[:DATA][:tags]

UPDATE:

when i’m trying to do

Rails.logger.debug(params[:DATA]) 

I get

{"tags":["dffdff"],"location_id":3,"post":{"content":"test #dffdff"}} 

but when I try

Rails.logger.debug(params[:DATA][:post]) 

I get

TypeError (can't convert Symbol into Integer):
  app/controllers/api/posts_controller.rb:19:in `[]'
  app/controllers/api/posts_controller.rb:19:in `create'
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T21:54:44+00:00Added an answer on June 4, 2026 at 9:54 pm

    Your issue is that params[:DATA] is a string, but you are treating it like a hash.

    You’ll need to parse the JSON-string into a Ruby hash, like so:

         data = JSON.parse(params[:DATA])
         puts data['post']
    

    If you want to use symbols in the hash, i.e. [:post], then you can do:

         data = data.with_indifferent_access
         puts data[:post]
    

    NB. If you want to test this out in a ruby console, rather than using params[:DATA], you can init data on the first line with:

         data = JSON.parse('{"tags":["dffdff"],"location_id":3,"post":{"content":"test #dffdff"}} ')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to send JSON post request to rails 3 server. I have
I have created a rails application that has a simple RESTful json API. This
We have a function in our Rails code that accepts a JSON POST body:
I have a controller method in Ruby on Rails 3 that accepts application/JSON as
I have an Ajax request from a page in my Rails app that looks
I have a hash being posted to my Rails app that looks like this:
I have the following POST request: POST http://blah/Request HTTP/1.1 Host: blah Content-Length: 322 Proxy-Connection:
Suppose we have the xhr 'POST' request that returns 'redirect' status code. In that
I have a program to send POST request to a server. I'm using cURL
Possible Duplicate: JavaScript post request like a form submit I have a value calculated

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.