如何使用Rails验证美国邮政编码?
我写了这样的东西,但它不起作用:
validates_format_of :zip_code,
:with => /^\d{5}(-\d{4})?$/,
:message => "Zip code should be valid"
Run Code Online (Sandbox Code Playgroud)
我使用如下代码在 Ruby 中解压文件:
def unzip_file (file)
Zip::ZipFile.open(file) do |zip_file|
zip_file.each do |f|
puts f.name if f.file?
end
end
end
Run Code Online (Sandbox Code Playgroud)
我想忽略 Mac 中 compress zip 生成的所有文件,例如:.DS_Store 等。我怎样才能最好地做到这一点?
我在Ruby中有这样的代码是否有可能写得更短?
first_name = person[0]
last_name = person[1]
person_id = person[2]
email = person[3]
title = person[4]
phone = person[5]
mobile = person[6]
department = person[7]
address = person[8]
city = person[9]
zip_code =person[10]
state =person[11]
country = person[12]
manager_id = person[13]
Run Code Online (Sandbox Code Playgroud)