我有此数组:查询对象不存在
--- !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