我在 erb(电子邮件模板)中显示重复的内容块,我想我会创建一个简单的类来代表每个块。
如果我手动渲染 erb,我尝试了类似的方法,但如果我尝试发送我抛出的电子邮件。
<%
class EmailBox
attr_accessor :text, :textLink,
end
x = EmailBox.new
x.textLink = 'https://www.google.com/'
x.text = 'blah'
@boxes = []
@boxes.push x
%>
<% @boxes.each do |row| %>
<a style="text-decoration:none;color:#666;" href="<%=row.textLink%>"><%=row.text%></a>
<% end %>
我得到的错误是:
/Users/x/appname/app/views/clip_mailer/send_clip_with_destination.html.erb:205: class definition in method body
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/actionpack-3.2.13/lib/action_view/template.rb:297:in `module_eval'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/actionpack-3.2.13/lib/action_view/template.rb:297:in `compile'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/actionpack-3.2.13/lib/action_view/template.rb:244:in `block in compile!'
<internal:prelude>:10:in `synchronize'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/actionpack-3.2.13/lib/action_view/template.rb:232:in `compile!'
我在重复自己,但是当我通过在磁盘上打开模板并运行来手动渲染模板时,这工作得很好ERB.new(file).result(binding)