如何为Spree API提供参数?

时间:2015-04-17 10:02:26

标签: ruby-on-rails spree

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

我在以下文件中添加了一个新参数:note:

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

但是,每次发送:note参数时,我都会在控制台中收到以下响应:

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

将允许的参数添加到Spree API调用的正确方法是什么?

我正在使用以下宝石:

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

我的Rails版本是:Rails 4.1.8

2 个答案:

答案 0 :(得分:3)

对于order_attributes,您将使用以下行

我相信你的order_decorator.rb:

Spree::PermittedAttributes.order_attributes << :your_attribute

答案 1 :(得分:1)

Spree为gem本身定义的允许参数使用每个模型的变量,您可以在spree配置中扩展它。

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

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

将customer_id添加到allowed_attributes