How can I code this so that the exception will output which method and specific instance of contact is the problem?
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}. ")
I would simply try a single message.gsub!() (mind the '!') per line, one for each attribute.
message.gsub!("{FirstName}", contact.first_name)
message.gsub!("{LastName}", contact.last_name)
This will save the message variable each time if something was changed, otherwise, it simply moves on to the next instance of gsub!.
精彩评论