2013-03-14 50 views
0

我有一个文本的UserMailer模板。在文本视图内我有以下内容:UserMailer在<% end %>错误在<% end %>为什么?

<% if [email protected]? %> 
    <% @thing.each do |id, count| %> 
    <%= #{count}%> <%= #{id} %> 
    <% end %> 
<% end %> 

这看起来不错,但它的错误?

ActionView::Template::Error: /app/views/user_mailer/user_daily_activity.text.erb:12: unterminated string meets end of file 
/app/views/user_mailer/myfile.text.erb:12: syntax error, unexpected $end, expecting ')' 

任何想法为什么轨道错误?谢谢

回答

4

#{count}格式只适用于字符串内,而不是作为独立的参考。由于您没有在字符串中使用它,#被解释为注释。

试试这个:

<%= count %> <%= id %> 

这也将是等效的:

<%= "#{count} #{id}" %> 
2

这是由于在.html.erb观点发表评论。你的第三行是作为评论。

<% if [email protected]? %> 
    <% @thing.each do |id, count| %> 
    <%= "#{count}" %> <%= "#{id}" %> 
    <% end %> 
<% end %> 
相关问题