1

Currently i'm trying to port my application to Rails 3.0 from 2.3.14 and I'm struck on the following error and this works fine in 2.3.14

My mailer code looks like

def welcome_mail(host,vendor_name,from, batch, sent_at = Time.now)
  template = MailTemplate.get_template(self.class.to_s,:welcome_mail.to_s,vendor_name,
              :greeting => batch.greeting, :batch => batch, :host =>host)
  @html_message = template.html_message
  @text_message = template.text_message
  mail( :subject => batch.subject, :to => get_recipients(batch), :from =>  from, :date =>  sent_at ) do |format|
    format.html
    format.text
  end
end

I pick up the email content from DB using MailTemplate model.

And my mailer view (welcome_mail.text.html.erb and welcome_mail.text.plain.erb contain only this line

<%=@html_message%> - welcome_mail.text.html.erb
<%=@text_message%> - welcome_mail.text.plain.erb

Inside the template, that is fetched from DB, i'm using a named route (which is a nested route) profile_batch_url and is supposed to produce a url like /profile/:profile_id/batch/:batch_id

But when I try to create a message

mail = UserMailer.welcome_email(request.host_with_port,get_vendor_name(),email, batch)

I'm getting the following error

NameError: undefined local variable or method `controller' for #<MailTemplate:0x000000060dff38>
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/activemodel-3.0.17/lib/active_model/attribute_methods.rb:392:in `method_missing'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.0.17/lib/active_record/attribute_methods.rb:46:in `method_missing'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/actionpack-3.0.17/lib/action_view/helpers/url_helper.rb:31:in `url_options'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/actionpack-3.0.17/lib/action_dispatch/routing/url_for.rb:131:in `url_for'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/actionpack-3.0.17/lib/action_view/helpers/url_helper.rb:99:in `url_for'
/usr/local/rvm/gems/ruby-1.9.3-p327/gems/actionpack-3.0.17/lib/action_dispatch/routing/route_set.rb:201:in `profile_batch_url'
(erb):5:in `text_message'

Can anyone help me in fixing this?

Thanks,
Sivakumar

4

0 回答 0