开发者

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=>'sampat开发者_StackOverflowh , :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


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')
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜