2013-03-14 49 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 %> 
相關問題