You can create a helper method to simplify working with nested hashes. Create the ruby_ext.rb file in your lib folder and write this function:
module RubyExt
module SafeHashChain
def safe(*args)
if args.size == 0 then self
elsif args.size == 1 then self[args[0]]
elsif self[args[0]].is_a?(Hash) then self[args[0]].safe(*args[1..-1])
else nil end
end
end
end
class Hash; include RubyExt::SafeHashChain; end
After that, you can call the safe method for nested hashes, for example:
params.safe(:order,:items_attributes)
It will return a value from items_attributes. If order or items_attributes does not exist, it will return zero.