开发者

ASIFormDataRequest to send post data to server rails, but in the insert have a null value

I'm using ASIFormDataRequest to send multipart POST data to a server rails.

The code snippet where I set the value with a text field and than send POST is below:

NSURL *url = [NSURL URLWithString:@"http://localhost:3000/users"];
ASIFormDataRequest *requestMsg = [[[ASIFormDataRequest alloc] initWithURL:url] autorelease]; 
[requestMsg setDelegate:self];
[requestMsg setPostValue:labelName.text forKey:@"name"];
[requestMsg startSynchronous];

In my rails log console I don't have any error and the post started correctly.

The problem is in the INSERT where the value of "name" is NULL:

Started POST "/users"
Parameters: {"name"=>"john"}
INSERT INTO "users" ("name", "created_at", "updated_at") VALUES (NULL, '2011-06-08 11:38:55.936498', '2011-06-08 11:38:55.936498')

Has anyone had this problem before?

This is the server side code

class UsersController < ApplicationController

# GET /users/new
def new
@user = User.new

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

# POST /users
def create
@user = User.new(params[:user])

respond_to do |format|
  if @user.save
    format.html { redirect_to(@user, :notice => 'User was successfully created.') }
    format.xml  { render :xml => @user, :status => :created, :location => @user }
  else
    format.html { render :action => "new" }
    f开发者_运维技巧ormat.xml  { render :xml => @user.errors, :status => :unprocessable_entity }
  end
end
end

end


My ruby isn't strong so don't shoot me if this is wrong. But shouldn't the line:

 @user = User.new(params[:user])

be

 @user = User.new(params[:name])

?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜