Fix undefine method `merge' for nil:NilClass error