2013-08-20 80 views
1

我有一个邮件看起来像(@user@foo传递到含方法):我有一些放测试它串插不打印变量的值,在打印精确的字符串

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') 

,把mail.body看起来像:

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

我只是误认为我如何做插值?它与ActionMailer有什么关系,或者将文本输出到控制台?

谢谢。在ruby

+1

使用'%Q考虑一个字符串,不引用,像这样的字符串插值:#{ruby_variable}!'如果你想使用引号但不能转义它们(引用:http://en.wikibooks.org/wiki/Ruby_Programming/Alternate_quotes) – MrYoshiji

回答

6

路线插值只能用双引号""

+1

或者heredocs,'%Q {...}','/.../'和'%r {...}'。 –

3

工作插值工作,则需要用双引号"不是单引号'

> a = 'test' 
=> "test" 
> 'Testing #{a}'  # This won't interpolate 
=> "Testing \#{a}" 
> "Testing {a}"  # This interpolates    
=> "Testing test"