2015-10-06 61 views
1

我正在使用葡萄和Rails建立一個API。一個端點接收對訂單的POST請求。該體系結構如下: 一個Order has_many OrderDetailsOrderDetails has_many OrderDetailCustomFields紅寶石葡萄 - 要求方法不工作3級深

因此,我期望POST請求JSON對象將嵌套三個深度的值。 我的代碼查找我的訂單端點: (裸記住我已經擺脫了大多數其他領域,所以那些誰幫我可以看看參數要求只是嵌套)

params do 
    requires :order, :type => Hash do 
     requires :order_details, :type => Array do 
      requires :order_detail, :type => Hash do 
       requires :cost, type: Integer#, desc: 
       requires :quantity_ordered, type: Integer#, desc: 
       requires :item_id, type: Integer#, desc: 
       optional :order_detail_custom_fields, :type => Array do 
        optional :order_detail_custom_field, :type => Hash do 
         requires :field_name, type: String#, desc: 
         optional :field_value, type: String#, desc: 
        end 
       end 
      end 
     end 
    end 
end 

我有其他有可選數組和可選哈希的端點。如果這些可選陣列或散列中的嵌套字段爲要求,則如果請求中存在父參數,葡萄通常只會拋出一個錯誤。

但是在:order_detail_custom_field的情況下並非如此。一旦我從2個參數級別深入到3個參數級別深度,葡萄就會吠叫我,並且似乎使所有:order_details哈希都需要整個:order_detail_custom_field陣列。即使它是可選的。其他:order_detail沒有custom_fields的散列現在出現錯誤,說明它們需要:field_name代替:order_detail_custom_field

確切的錯誤是:

{ 
error: order[order_details][order_detail][order_detail_custom_fields][order_detail_custom_field][field_name] is missing 
} 

我能看到的唯一區別是,錯誤似乎發生於3個層次深,而不是2層深的參數。有人對此有經驗嗎?或者我忽略了什麼?

+1

對於任何人在這個問題上磕磕絆絆,我提交了一個標有「bug?」的github問題。 。我會更新,因爲我有更多的信息。 – James

+0

此問題仍在發生。 – juliangonzalez

回答

1

對於任何人在這個問題上磕磕絆絆,我提交了一個標有「bug?」的github問題。據我所知,這個問題仍在按@JGonzalesD進行。