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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:50:28+00:00 2026-05-15T18:50:28+00:00

I am trying to send a POST request to my Ruby on Rails local

  • 0

I am trying to send a POST request to my Ruby on Rails local server. Unfortunately, at first it wouldn’t let me POST because of protect_from_forgery, so I ended up setting it to false in development and production. Basically, my issue is that I’ll send the POST request from my Cocoa app with all of the wanted params, and the Ruby server will see it. However, whenever the server inserts my request all of the VALUES are set to NULL with the exception of created_at and updated_at. I do not know how Ruby on Rails works (since I used scaffold), so I am not sure where I need to set the params so that they will be inserted properly.

Thanks!

COCOA CODE:

NSString *urlString = @"http://localhost:3000/clients";
NSURL *url = [[NSURL alloc] initWithString:urlString];
NSMutableURLRequest *req = [[NSMutableURLRequest alloc] initWithURL: url];
[req setHTTPMethod: @"POST"];

NSData *putParams = [@"name=TEST&ip_address=1.1.1.1" dataUsingEncoding:NSUTF8StringEncoding];
[req setHTTPBody: putParams];   

NSHTTPURLResponse* urlResponse = nil;  
NSError *error = [[NSError alloc] init];  
NSData *responseData = [NSURLConnection sendSynchronousRequest:req returningResponse:&urlResponse error:&error];  
NSString *result = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];

NSLog(@"Response Code: %d", [urlResponse statusCode]);
if ([urlResponse statusCode] >= 200 && [urlResponse statusCode] < 300)
    NSLog(@"Response: %@", result);

[url release];
[req release];
[error release];

SERVER RESPONSE:

Processing ClientsController#create (for 17.224.23.62 at 2010-07-13 16:59:55) [POST]
Parameters: {"name"=>"TEST", "ip_address"=>"1.1.1.1"}
Client Create (0.3ms)   INSERT INTO "clients" ("name", "created_at", "updated_at", "ip_address") VALUES(NULL, '2010-07-13 23:59:55', '2010-07-13 23:59:55', NULL)
Redirected to http://17.224.23.62:3000/clients/6
Completed in 7ms (DB: 0) | 302 Found [http://17.224.23.62/clients]

Processing ClientsController#show (for 17.224.23.62 at 2010-07-13 16:59:55) [GET]
Parameters: {"id"=>"6"}
Client Load (0.1ms)   SELECT * FROM "clients" WHERE ("clients"."id" = 6) 
Rendering template within layouts/clients
Rendering clients/show
Completed in 7ms (View: 2, DB: 0) | 200 OK [http://17.224.23.62/clients/6]

I TRIED TO DO THIS IN CLIENTS CONTROLLER BUT ISSUE REMAINED THE SAME:

if params[:name].present?
  @client = Client.new(:name => params[:names])
else
  @client = Client.new(params[:client])
end

JUST IN CASE IT IS NEEDED (FULL CLIENT CONTROLLER – ALL OF IT WAS WITH SCAFFOLD):

class ClientsController < ApplicationController

# GET /clients
# GET /clients.xml
def index
  @clients = Client.all

  respond_to do |format|
    format.html # index.html.erb
    format.xml  { render :xml => @clients }
  end
end

# GET /clients/1
# GET /clients/1.xml
def show
  @client = Client.find(params[:id])

  respond_to do |format|
    format.html # show.html.erb
    format.xml  { render :xml => @client }
  end
end

# GET /clients/new
# GET /clients/new.xml
def new
  @client = Client.new

  respond_to do |format|
    format.html # new.html.erb
    format.xml  { render :xml => @client }
  end
end

# GET /clients/1/edit
def edit
  @client = Client.find(params[:id])
end

# POST /clients
# POST /clients.xml
def create
  if params[:name].present?
    @client = Client.new(:name => params[:names])
  else
    @client = Client.new(params[:client])
  end

  respond_to do |format|
    if @client.save
      format.html { redirect_to(@client, :notice => 'Client was successfully created.') }
      format.xml  { render :xml => @client, :status => :created, :location => @client }
    else
      format.html { render :action => "new" }
      format.xml  { render :xml => @client.errors, :status => :unprocessable_entity }
    end
  end
end

# PUT /clients/1
# PUT /clients/1.xml
def update
  @client = Client.find(params[:id])

  respond_to do |format|
    if @client.update_attributes(params[:client])
      format.html { redirect_to(@client, :notice => 'Client was successfully updated.') }
      format.xml  { head :ok }
    else
      format.html { render :action => "edit" }
      format.xml  { render :xml => @client.errors, :status => :unprocessable_entity }
    end
  end
end

# DELETE /clients/1
# DELETE /clients/1.xml
def destroy
  @client = Client.find(params[:id])
  @client.destroy

  respond_to do |format|
    format.html { redirect_to(clients_url) }
    format.xml  { head :ok }
  end
end

end

P.S. If something about my question is unclear, please let me know.

  • 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-15T18:50:29+00:00Added an answer on May 15, 2026 at 6:50 pm

    You have a typo in your controller: @client = Client.new(:name => params[:names]) should be @client = Client.new(:name => params[:name]).

    That would solve part of the issue but here is the root of it:

    Essentially, if this were a “real” Rails app it would send params like this:

    { :client => { :name => x, :ip => y } }
    

    And then you could access the name and IP in params[:client] like so:

    @client = Client.new(params[:client])
    

    But you are sending:

    { :name => x, :ip => y }
    

    So you need:

    @client = Client.new(:name => params[:name], :ip => params[:ip])
    

    For the “Rails way” to work, you could modify your Objective-C code to send params like client[name]=x&client[ip]=y.

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

Sidebar

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.