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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:21:28+00:00 2026-06-06T07:21:28+00:00

this newbie here is smacking his head with webservices over Rails. Perhaps someone could

  • 0

this newbie here is smacking his head with webservices over Rails.
Perhaps someone could ease my pain?

I’ve created a simple rails app, and generated the scaffold MyRecords. Then I’m trying to create a record over irb with the code below :

testWS.rb

require 'HTTParty'

class MyRecordCreate
  include HTTParty
  base_uri 'localhost:3000'

  def initialize(u, p)
    @auth = {:username => u, :password => p}
  end

  def post(text)
    options = { :body => { name:text} }
    self.class.post('/my_records', options)
  end
end


response = HTTParty.get("http://localhost:3000/my_records/new.json")
print response

record = MyRecordCreate.new("","").post("test remote record")
print record

With the code above, I managed to create a record. the thing is that my Record (which only has the column “name”) is created with an empty name!

Any suggestions on this one?

I’m longing to slice this despair piece by piece.

Thank you for your contribute.

  • 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-06T07:21:30+00:00Added an answer on June 6, 2026 at 7:21 am

    Try adding these two lines to your HTTParty class:

    format :json
    headers "Accept" => "application/json"
    

    These tell httparty and the remote service to which it connects to send and receive JSON. For your example (with .json at the end of the URL) it isn’t necessary to add the second line, but I find it is good practice and keep it anyway.

    The next problem is that Rails expects your uploaded data to be inside the top level name of your object. So, for your example, the options line should look something like:

    options = { :body => { :person => { :name => text } } }
    

    Replace person with the name of the model that you are attempting to create.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Rails newbie here so just want to be sure I'm doing this right. I
Android newbie here. I'm using this tutorial to show some rows that I fetch
Im sure this is simple but newbie here. I have 5 URLS cards.php&type=one cards.php&type=two
Forgive the complete newbie question here - I know this is really basic stuff,
I'm a newbie to sql and am trying to follow this example here: http://net.tutsplus.com/tutorials/php/a-better-login-system/
I am a regex newbie and can't seem to figure this one out. Here
I'm newbie with Nhibernate. Hope I can find the answer here. This is my
I'm trying to solve this newbie puzzle: I've created this function: def bucket_loop(htable, key):
Perl newbie here...I had help with this working perl script with some HASH code
c# newbie here. seems like this user gave me a very good solution for

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.