2015-04-17 62 views
2

如何为Spree API请求准许参数?如何允许Spree API的参数?

我添加了一个新的参数,:请注意,在以下文件:

spree_api /应用/助理/大礼包/ API/api_helpers.rb

Spree::Api::ApiHelpers.module_eval do 
    @@order_attributes = [ 
    :id, :number, :item_total, :total, :ship_total, :state, :adjustment_total, 
    :user_id, :created_at, :updated_at, :completed_at, :payment_total, 
    :shipment_state, :payment_state, :email, :special_instructions, :channel, 
    :included_tax_total, :additional_tax_total,  :display_included_tax_total, 
    :display_additional_tax_total, :tax_total, :currency, :notes 
    ] 
end 

但是,每次我发时间:注参数,我得到了我的控制台以下回应:

Unpermitted parameters: id, number, item_total, total, state, adjustment_total, user_id, completed_at, payment_total, shipment_state, payment_state, created_at, updated_at, currency, additional_tax_total, channel, included_tax_total, notes 

什么是允许的PARAMS添加到狂欢API调用的正确方法?

我用下面的宝石:

spree (2.4.3.beta) 
    spree_api (= 2.4.3.beta) 

我的Rails的版本是:Rails的4.1.8

+0

看来你的请求有一些错误的参数名称。请提供完整的请求代码。 –

回答

1

施普雷使用在宝石本身定义的参数允许每个模型中的变量,可以延长这在疯狂的配置。

order_attributes您可以使用以下行config/initializers/spree.rb

Spree::Api::ApiHelpers.order_attributes << :customer_id 

到CUSTOMER_ID添加到permitted_attributes

+0

看来我不得不使用Spree :: Api :: ApiHelpers.order_attributes <<:注释来扩展API允许的属性。非常感谢! :-) – Vernon

+0

@Vernon如果解决了这个问题,你能否接受它作为最佳答案?感谢名单! –

3

order_attributes你可以使用下面的行

我相信这在你的order_decorator .rb:

Spree::PermittedAttributes.order_attributes << :your_attribute