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

skaffman
  • 398,947
  • 96
  • 818
  • 769
  • http://stackoverflow.com/questions/2918419/add-api-key-to-every-request-in-activeresource ?? – Fivell Mar 31 '11 at 14:30

1 Answers1

2

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')
mind.debug
  • 283
  • 2
  • 10