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

  • Home
  • SEARCH
  • 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 8369735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:43:37+00:00 2026-06-09T13:43:37+00:00

I created a REST server with Rails that manages Users and associated Comments .

  • 0

I created a REST server with Rails that manages Users and associated Comments.
Here is the routes configuration.

resources :users do
  resources :comments
end

In the controller I only need actions to query and create Comments. The exchange format is JSON.

class CommentsController < ApplicationController

  def index
    @user = User.find(params[:user_id])
    @comments = @user.comments  
    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @comments }
    end
  end

  def create
    @user = User.find(params[:user_id])
    @comment = @user.comments.create!(params[:comment])
    redirect_to @user
  end

end

I would like to store Comments created by a remote client. It is an Android application. To test the server I am trying the following curl commands, as suggested here.

curl -X POST -d @comment1.json http://localhost:3000/users/42/comments
curl -X POST -d @comment1.json http://localhost:3000/users/42/comments.json
curl -X POST -d @comment2.json http://localhost:3000/users/42/comments
curl -X POST -d @comment2.json http://localhost:3000/users/42/comments.json

I am also not sure how the JSON file has to look like. Here are the variations I tried:
comment1.json

{
  content:
  {
    message: "Let's see if this works.",
    subject: "JSON via curl"
  }
}

… or comment2.json

{
  message: "Let's see if this works.",
  subject: "JSON via curl"
}

When I check the Comments on the particular User I can see that it has been created, however, the parameters subject and message, I passed, get lost somewhere!

[
  {
    created_at: "2012-08-11T20:00:00Z",
    id: 6,
    message: "null",
    subject: "null",
    updated_at: "2012-08-11T20:00:00Z",
    user_id: 42
  }
]

The Rails installation includes the following gems.

...
Using multi_json (1.3.6) 
Using json (1.7.4)
...

Question:

  • How can I test the creation of Comments via curl or with any other suitable tool?
  • 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-09T13:43:39+00:00Added an answer on June 9, 2026 at 1:43 pm

    Try setting the content-type header with -H "Content-Type:application/json".
    I think Rails is looking for the post parameters as form data (eg. content[subject]='JSON via curl').

    Further, the JSON file is not valid. JSON keys need to be quoted, too. Use the following file …

    {
      "message": "Let's see if this works.",
      "subject": "JSON via curl"
    }
    

    and send it with one of these commands …

    curl -X POST -H "Content-Type:application/json" -d @comments2.json http://localhost:3000/users/42/comments
    curl -X POST -H "Content-Type:application/json" -d @comments2.json http://localhost:3000/users/42/comments.json
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a REST server under ASP.NET and I can't figure out the
I created a WCF rest service, then called that from javascript using ajax. Now
I want to develop my own REST service, so I've created an IHttpHandler that
I'm having a mysterious bug where a rest call that I've created on my
Started building an application here. client and server style architecture sending active resources across
I created simple REST web app that would create Excel file and put into
I have successfully created a PHP REST API which resides on my server. I
I'm taking the database that I created with SQL server express and putting it
Is possible to create a fully-featured REST server with Ruby (not Rails)?
I created a simple DataSnap REST server in Delphi XE2 and i have a

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.