3

I wanna create a new customer through activeresource. without authentication_key its not a big deal. i'm using devise authentication and cancan.

customer = Customer.create(:fname=>'sampath , :last_name=>'munasinghe' ,:auth_token=>'af34afafasfasfasaf')

if I use above code to create a new customer , xml request to web server is

Parameters: {"customer"=>{"first_name"=>'sampath', "last_name"=>"munasinghe", "auth_token"=>"af34afafasfasfasaf"}}

problem id auth_token wrapped by the customer model. so , authentication failed and returned 401 response.

is there any solution to create this format of request?

Parameters: {"customer"=>{"first_name"=>'sampath', "last_name"=>"munasinghe"}, "auth_token"=>"af34afafasfasfasaf"}}

note : auth_token is outside the customer block.

thanks

4

1 回答 1

2

对于 json,最简单的方法是将 Customer.include_root_in_json 设置为 false。

然后使用此代码:

customer = Customer.create(:customer => [:fname=>'sampath' , :last_name=>'munasinghe'],:auth_token=>'af34afafasfasfasaf')
于 2011-03-31T14:36:03.990 回答