我有此數組:查詢對象不存在
--- !map:ActiveSupport::HashWithIndifferentAccess
search: !map:ActiveSupport::HashWithIndifferentAccess
address: test
我申請以下它:
address = params['search']['address']
if address
# do something
end
如果沒有搜索對象,也沒有地址對象,代碼產生了一個錯誤:
You have a nil object when you didn't expect it! You might have expected an instance of Array. The error occurred while evaluating nil.[]
在ruby中處理類似的東西的方式是什麼?
作爲JITS所指出的,你可能有一個數組。在ruby中評論不是'//',它是'#'。我修好了它。 – sawa 2011-06-05 22:15:33
謝謝sawa。 – choise 2011-06-06 08:38:02