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 6086401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:45:02+00:00 2026-05-23T11:45:02+00:00

I am trying to create a new User in a MongoDB/Sinatra Server from a

  • 0

I am trying to create a new “User” in a MongoDB/Sinatra Server from a Rails3 Client using ActiveResource and Json and the object body or hash that is sent is empty. In Rails3, I created a “User” model and using the Rails Console I make an ActiveResource call to the Sinatra Server. The Server correctly reads the URL, but no parameters seem to get passed with the object. Can someone please give me their thoughts as to what I have missed or why I am not getting the correct output?

Sinatra Server uses Ruby 1.8.7.
Rails3 Client uses Ruby 1.9.2.

From Rails3 Client User Model:

class User < ActiveResource::Base 
   self.site = "http://127.0.0.1:9393/"
   self.collection_name = "user/add"
   self.format = :json 
end

From the Rails3 console:

u=User.new(:first_name=>"Bill",:last_name=>"Smith")
=> #<User:0xa8d7fac @attributes={"first_name"=>"Bill", "last_name"=>"Smith"}, @prefix_options={}>
u.save
=> True

The Sinatra app server receives the following object (which I retrieve from the Sinatra server using “puts @app.inspect”):

 #<Api:0xb6ee4e70 @block_params=[], @result={"status"=>200, "error"=>nil}, @params={}, @observer_state=true, @request=#<Sinatra::Request:0xb6ee4e0c @params={}, @route="/user/add.json", @env={"HTTP_HOST"=>"127.0.0.1:9393", "HTTP_ACCEPT"=>"*/*", "SERVER_NAME"=>"127.0.0.1", "REQUEST_PATH"=>"/user/add.json", "rack.url_scheme"=>"http", "HTTP_USER_AGENT"=>"Ruby", "REMOTE_HOST"=>"localhost", "CONTENT_LENGTH"=>"50", "rack.errors"=>#<Rack::Lint::ErrorWrapper:0xb6ee5294 @error=#<IO:0xb77e955c>>, "SERVER_PROTOCOL"=>"HTTP/1.1", "CONTENT_TYPE"=>"application/json", "rack.version"=>[1, 1], "rack.run_once"=>false, "SERVER_SOFTWARE"=>"WEBrick/1.3.1 (Ruby/1.8.7/2011-02-18)", "REMOTE_ADDR"=>"127.0.0.1", "PATH_INFO"=>"/user/add.json", "SCRIPT_NAME"=>"", "HTTP_VERSION"=>"HTTP/1.1", "rack.multithread"=>true, "rack.multiprocess"=>false, "REQUEST_URI"=>"http://127.0.0.1:9393/user/add.json", "rack.request.query_hash"=>{}, "SERVER_PORT"=>"9393", "REQUEST_METHOD"=>"POST", "rack.request.query_string"=>"", "rack.input"=>#<Rack::Lint::InputWrapper:0xb6ee52d0 @input=#<StringIO:0xb76fbeb0>>, "HTTP_CONNECTION"=>"close", "QUERY_STRING"=>"", "GATEWAY_INTERFACE"=>"CGI/1.1"}>, @original_params={}, @template_cache=#<Tilt::Cache:0xb6ee4fb0 @cache={}>, @env={"HTTP_HOST"=>"127.0.0.1:9393", "HTTP_ACCEPT"=>"*/*", "SERVER_NAME"=>"127.0.0.1", "REQUEST_PATH"=>"/user/add.json", "rack.url_scheme"=>"http", "HTTP_USER_AGENT"=>"Ruby", "REMOTE_HOST"=>"localhost", "CONTENT_LENGTH"=>"50", "rack.errors"=>#<Rack::Lint::ErrorWrapper:0xb6ee5294 @error=#<IO:0xb77e955c>>, "SERVER_PROTOCOL"=>"HTTP/1.1", "CONTENT_TYPE"=>"application/json", "rack.version"=>[1, 1], "rack.run_once"=>false, "SERVER_SOFTWARE"=>"WEBrick/1.3.1 (Ruby/1.8.7/2011-02-18)", "REMOTE_ADDR"=>"127.0.0.1", "PATH_INFO"=>"/user/add.json", "SCRIPT_NAME"=>"", "HTTP_VERSION"=>"HTTP/1.1", "rack.multithread"=>true, "rack.multiprocess"=>false, "REQUEST_URI"=>"http://127.0.0.1:9393/user/add.json", "rack.request.query_hash"=>{}, "SERVER_PORT"=>"9393", "REQUEST_METHOD"=>"POST", "rack.request.query_string"=>"", "rack.input"=>#<Rack::Lint::InputWrapper:0xb6ee52d0 @input=#<StringIO:0xb76fbeb0>>, "HTTP_CONNECTION"=>"close", "QUERY_STRING"=>"", "GATEWAY_INTERFACE"=>"CGI/1.1"}, @app=nil, @observer_peers=[#<HookMongo:0xb6d714f8 @extra=nil, @app=#<Api:0xb6ee4e70 ...>>], @response=#<Sinatra::Response:0xb6edb94c @writer=#<Proc:0xb77cd4b0@/home/scott/.rvm/gems/ruby-1.8.7-p334@api/gems/rack-1.3.0/lib/rack/response.rb:28>, @block=nil, @chunked=false, @length=0, @header={"Content-Type"=>nil}, @body=[], @status=200>>

As you can see the @params={} is empty.

Using the HTTP request works:

Net::HTTP.post_form(URI.parse('http://127.0.0.1:9393/user/add.json'),{'first_name' => 'Smith', 'last_name' => 'Bill'})

And produces this:

#<Api:0xb6ee4fec @block_params=[], @result={"status"=>200, "error"=>nil}, @params={"last_name"=>"Bill", "first_name"=>"Smith"}, @observer_state=true, @request=#<Sinatra::Request:0xb6ee4f88 @params={"last_name"=>"Bill", "first_name"=>"Smith"}, @route="/user/add.json", @env={"HTTP_HOST"=>"127.0.0.1:9393", "HTTP_ACCEPT"=>"*/*", "SERVER_NAME"=>"127.0.0.1", "REQUEST_PATH"=>"/user/add.json", "rack.url_scheme"=>"http", "HTTP_USER_AGENT"=>"Ruby", "REMOTE_HOST"=>"localhost", "CONTENT_LENGTH"=>"31", "rack.errors"=>#<Rack::Lint::ErrorWrapper:0xb6ee5410 @error=#<IO:0xb77e955c>>, "SERVER_PROTOCOL"=>"HTTP/1.1", "CONTENT_TYPE"=>"application/x-www-form-urlencoded", "rack.version"=>[1, 1], "rack.run_once"=>false, "SERVER_SOFTWARE"=>"WEBrick/1.3.1 (Ruby/1.8.7/2011-02-18)", "REMOTE_ADDR"=>"127.0.0.1", "PATH_INFO"=>"/user/add.json", "SCRIPT_NAME"=>"", "HTTP_VERSION"=>"HTTP/1.1", "rack.multithread"=>true, "rack.request.form_vars"=>"first_name=Smith&last_name=Bill", "rack.multiprocess"=>false, "REQUEST_URI"=>"http://127.0.0.1:9393/user/add.json", "rack.request.form_input"=>#<Rack::Lint::InputWrapper:0xb6ee544c @input=#<StringIO:0xb76d72a4>>, "rack.request.query_hash"=>{}, "SERVER_PORT"=>"9393", "REQUEST_METHOD"=>"POST", "rack.request.form_hash"=>{"last_name"=>"Bill", "first_name"=>"Smith"}, "rack.request.query_string"=>"", "rack.input"=>#<Rack::Lint::InputWrapper:0xb6ee544c @input=#<StringIO:0xb76d72a4>>, "QUERY_STRING"=>"", "GATEWAY_INTERFACE"=>"CGI/1.1"}>, @original_params={"last_name"=>"Bill", "first_name"=>"Smith"}, @template_cache=#<Tilt::Cache:0xb6ee512c @cache={}>, @env={"HTTP_HOST"=>"127.0.0.1:9393", "HTTP_ACCEPT"=>"*/*", "SERVER_NAME"=>"127.0.0.1", "REQUEST_PATH"=>"/user/add.json", "rack.url_scheme"=>"http", "HTTP_USER_AGENT"=>"Ruby", "REMOTE_HOST"=>"localhost", "CONTENT_LENGTH"=>"31", "rack.errors"=>#<Rack::Lint::ErrorWrapper:0xb6ee5410 @error=#<IO:0xb77e955c>>, "SERVER_PROTOCOL"=>"HTTP/1.1", "CONTENT_TYPE"=>"application/x-www-form-urlencoded", "rack.version"=>[1, 1], "rack.run_once"=>false, "SERVER_SOFTWARE"=>"WEBrick/1.3.1 (Ruby/1.8.7/2011-02-18)", "REMOTE_ADDR"=>"127.0.0.1", "PATH_INFO"=>"/user/add.json", "SCRIPT_NAME"=>"", "HTTP_VERSION"=>"HTTP/1.1", "rack.multithread"=>true, "rack.request.form_vars"=>"first_name=Smith&last_name=Bill", "rack.multiprocess"=>false, "REQUEST_URI"=>"http://127.0.0.1:9393/user/add.json", "rack.request.form_input"=>#<Rack::Lint::InputWrapper:0xb6ee544c @input=#<StringIO:0xb76d72a4>>, "rack.request.query_hash"=>{}, "SERVER_PORT"=>"9393", "REQUEST_METHOD"=>"POST", "rack.request.form_hash"=>{"last_name"=>"Bill", "first_name"=>"Smith"}, "rack.request.query_string"=>"", "rack.input"=>#<Rack::Lint::InputWrapper:0xb6ee544c @input=#<StringIO:0xb76d72a4>>, "QUERY_STRING"=>"", "GATEWAY_INTERFACE"=>"CGI/1.1"}, @app=nil, @observer_peers=[#<HookMongo:0xb6d68c18 @extra=nil, @app=#<Api:0xb6ee4fec ...>>], @response=#<Sinatra::Response:0xb6edbac8 @writer=#<Proc:0xb77cd4b0@/home/scott/.rvm/gems/ruby-1.8.7-p334@api/gems/rack-1.3.0/lib/rack/response.rb:28>, @block=nil, @chunked=false, @length=0, @header={"Content-Type"=>nil}, @body=[], @status=200>>

@params={“last_name”=>”Bill”, “first_name”=>”Smith”} is no longer empty.

In the active_resource/connection.rb file, line 94

# Executes a POST request.
# Used to create new resources.
def post(path, body = '', headers = {})
  with_auth { request(:post, path, body.to_s, build_request_headers(headers, :post, self.site.merge(path))) }
end

I’m sure I’m missing something, but this seems to create a empty body.

Thanks for your advice in advance.

  • 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-05-23T11:45:03+00:00Added an answer on May 23, 2026 at 11:45 am

    Sinatra doesn’t parse the body by default. If there is a form encoding header, Rack will parse the form encoded body and put it in the params which is why using post_form works. You need to pull the request body out and parse it yourself. e.g.

    post '/add' do
      user_hash = JSON.parse request.body
      User.create! user_hash
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a new user on my development active directory server using
I'm trying to create a new user record into OpenLDAP with object classes person
I'm trying to create a user acount on my rails backend via json from
I am trying to create a new user object with a specific Role. The
In a view I'm trying to create a new user and then log them
Im trying to test my successfully creates a new user after login (using authlogic).
I'm trying to create a new Excel file using jxl, but am having a
I am trying to create a new contact using Dynamic Entity. The sample i
I am trying to create a new website on a remote server via msbuild
I'm trying to create a new object of type T via its constructor when

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.