36

本质上我正在尝试进行这种比较

request.fullpath == "/contacts/"+current_user.id

将字符串与变量连接以执行这样的比较的最佳方法是什么?

4

2 回答 2

77

您可以将其插入为 request.fullpath == "/contacts/#{current_user.id}"

于 2012-11-26T03:29:38.830 回答
24
"/contacts/#{current_user.id}"

始终使用字符串插值,它比<<+

于 2012-11-26T03:30:53.130 回答