【问题标题】:custom parameter for activeresource活动资​​源的自定义参数
【发布时间】:2011-03-31 22:36:03
【问题描述】:

我想通过 activeresource 创建一个新客户。没有 authentication_key 没什么大不了的。我正在使用设计身份验证和 cancan。

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

如果我使用上面的代码创建一个新客户,对 web 服务器的 xml 请求是

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

客户模型包装的问题 id auth_token。因此,身份验证失败并返回 401 响应。

有什么解决方案可以创建这种格式的请求吗?

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

注意:auth_token 在客户块之外。

谢谢

【问题讨论】:

标签: ruby-on-rails activeresource


【解决方案1】:

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

然后使用这个代码:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-09-08
    • 1970-01-01
    • 1970-01-01
    • 2021-09-05
    • 1970-01-01
    • 1970-01-01
    • 2020-06-12
    相关资源
    最近更新 更多