If you find yourself doing a lot of these you could write a little helper method:
def set_unless_nil(hsh, key, val)
hsh[key] = val unless val.nil?
end
and then:
set_unless_nil filters, :red, params[:search][:red]
And if the key in the source and destination hashes is frequently the same you could write:
def copy_key_unless_nil(src_hash, key, dest_hash)
dest_hash[key] = src_hash[key] unless src_hash[key].nil?
end
and then:
copy_key_unless_nil params[:search], :red, filters
Alternatively you could just set the values into the Hash anyway and then tidy the hash at the end to remove all the keys with a nil value:
filters.delete_if { |k, v| v.nil? }