1

I have a mailer that looks like (@user and @foo are passed to the containing method):

mail(to: @user.email, subject: 'Foo is expired', 
    body: 'Your Foo reservation for #{@foo.bar.name} in position #{@foo.position}
    has expired.  Please recreate the reservation if necessary')

I'm testing it with some puts, puts mail.body looks like:

'Your Foo reservation for #{@foo.bar.name} in position #{@foo.position}
 has expired.  Please recreate the reservation if necessary'

Am I just mistaken on how I'm doing interpolation? Has it something to do with ActionMailer, or outputting text to console?

Thanks.

4

2 回答 2

6

字符串插值ruby仅适用于双引号""

于 2013-08-20T19:00:17.190 回答
3

要使插值起作用,您需要使用双引号"而不是单引号'

> a = 'test'
 => "test" 
> 'Testing #{a}'     # This won't interpolate
 => "Testing \#{a}" 
> "Testing {a}"      # This interpolates               
 => "Testing test" 
于 2013-08-20T19:00:27.923 回答