Sampath Munasinghe
Sampath Munasinghe

Reputation: 129

custom parameter for activeresource

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

Upvotes: 3

Views: 1101

Answers (1)

mind.debug
mind.debug

Reputation: 283

For json the simplest way to do that is setting Customer.include_root_in_json to false.

Then use this code:

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

Upvotes: 2

Related Questions