2015-04-17 27 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