Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 958
Sampath Munasinghe Avatar asked Dec 08 '25 09:12

Sampath Munasinghe


1 Answers

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')
like image 173
mind.debug Avatar answered Dec 10 '25 00:12

mind.debug



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!