Topic: undefined method `controller_path' for SiteMailer:Class

I am trying to use the "render" method in a view under a SiteMailer class and it spits out:

undefined method `render' for SiteMailer:Class

When i prepend the render method with ActionController::Base, it still doesn't work and spits out:

NoMethodError in Events#post

Showing app/views/site_mailer/alert.rhtml where line #3 raised:

undefined method `render' for ActionController::Base:Class

Extracted source (around line #3):

1: Heads up!
2: <% if @alert.type.downcase == 'event' %>
3: <% ActionController::Base.render :partial => 'event' %>
4: A brand spankin' new event has been posted.
5:
6: *************************** NEW EVENT LISTING! ***************************

RAILS_ROOT: ./script/../config/..
Application Trace | Framework Trace | Full Trace

#{RAILS_ROOT}/app/views/site_mailer/alert.rhtml:3:in `_run_rhtml_alert'
#{RAILS_ROOT}/app/controllers/post_controller.rb:209:in `send_alerts'
#{RAILS_ROOT}/app/controllers/post_controller.rb:192:in `send_alerts'
#{RAILS_ROOT}/app/controllers/post_controller.rb:69:in `post'
#{RAILS_ROOT}/app/controllers/post_controller.rb:62:in `post'
-e:4


Help...what's the deal?

Re: undefined method `controller_path' for SiteMailer:Class

Looks like you are trying to call render on the class, but it expects it to be called on an instance.

Can you post your Mailer code? You don't have "self." in front of the action method definition, do you?

Railscasts - Free Ruby on Rails Screencasts

Re: undefined method `controller_path' for SiteMailer:Class

Sure...thanks for the quick response! 

This is what I assume you mean...the view code?  (btw, @alert.type = 'event')

Heads up!

<%= ActionController::Base.render :partial => @alert.type %>

Manage your alerts:
http://www.myurl.org/account/alerts

Post Jobs and/or Resumes:
http://www.myurl.org/employment

Browse Directory of over 2000 Savannah Businesses:
http://www.myurl.org/directory


Just in case you didn't mean the view, here is the code from the site_mailer model...though I'm not sure it would matter. (Yes, I'm a newbie!)

  
class SiteMailer < ActionMailer::Base

  def alert(users, alertitem)
    alert_item = alertitem
    singulars = {'Property' => 'real_estate', 'Article' => 'news', 'Link' => 'directory'}
    singulars.include?(alert_item.type) ? email = singulars[alert_item.type] : email = alert_item.type.downcase + 's'
    alert_item.type = singulars[alert_item.type] unless !singulars.include?(alert_item.type)
   
    @headers = {}
    @sent_on = Time.now
    @from = 'The Creative Coast Initiative <' + email + '@thecreativecoast.org>'
    @recipients = email + '@creativecoast.org'
    @bcc = users
    alert_item.type.gsub!("_"," ")
    @subject = 'TCCi ' + alert_item.type + ' Alert: ' + alert_item.title
    @body = {}
    @body['alert'] = alert_item
  end
end

Re: undefined method `controller_path' for SiteMailer:Class

Doing this returns the error you metioned above?

<%= render :partial => @alert.type %>

I've honestly never tried rendering partials in a mailer view. I wonder if it's even supported...

Railscasts - Free Ruby on Rails Screencasts

Re: undefined method `controller_path' for SiteMailer:Class

Yup...that's what I did. I figured I could use the class and it would work. Why isn't this the case?

Re: undefined method `controller_path' for SiteMailer:Class

Because "render" is an instance method, not a class method, so you would have to create an instance of the controller (with the new method or something) before calling render.

However, I do not think this is a good solution. It doesn't look like ActionMailer supports partials. See this ticket for discussion and workarounds.

Railscasts - Free Ruby on Rails Screencasts