我不断收到can't conversion nil to String but can't debugd in Rails 3
我该如何编码,以便异常将输出哪个方法和具体的联系实例是问题所在?
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}. ")
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}. ")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会简单地每行尝试一个 message.gsub!() (注意“!”),每个属性一个。
如果每次发生更改,这将保存消息变量,否则,它只是移动到 gsub! 的下一个实例。
I would simply try a single message.gsub!() (mind the '!') per line, one for each attribute.
This will save the message variable each time if something was changed, otherwise, it simply moves on to the next instance of gsub!.