0

我该如何编码,以便异常输出哪个方法和特定的联系实例是问题?

 sub_message =
 13       message.gsub("{FirstName}", contact.first_name).
 14            gsub("{LastName}", contact.last_name).
 15            gsub("{Title}", contact.title || "blank").
 16            gsub("{Signature}", contact.user.signature.to_s).
 17        #    gsub("{Company}", contact.company_name.clear_company).
 18            gsub("{Colleagues}", colleagues.to_sentence).
 19            gsub("{NextWeek}", next_week.strftime("%A, %B %d")).
 20            gsub("{FollowingWeek}", (Date.today + 14.days).strftime("%A, %B %d")).
 21            gsub("{UserFirstName}", contact.user.first_name).
 22            gsub("{UserLastName}", contact.user.last_name).
 23            gsub("{City}", contact.address.city.titleize || "default city").
 24            gsub("{State}", contact.address.state || "default state").
 25            gsub("{Zip}", contact.address.zip || "default zip" ).
 26            gsub("{Phone}", contact.phone.format_phone || "default phone" ).
 27            gsub("{Street1}", contact.address.street1.titleize || "default street").
 28            gsub("{Today}", (Date.today).strftime("%A, %B %d")).
 29            gsub("{CustomField1}", contact.custom_field_1.to_s || "custom").
 30            gsub("{PageBreak}", "p{page-break-after: always}. ")
4

1 回答 1

0

我会简单地尝试每行一个 message.gsub!() (注意'!'),每个属性一个。

message.gsub!("{FirstName}", contact.first_name)
message.gsub!("{LastName}", contact.last_name)

这将在每次发生更改时保存消息变量,否则,它只会移动到 gsub! 的下一个实例。

于 2012-01-03T05:41:51.747 回答