# ActionMailer Views Confusion

**URL:** <https://www.ruby-forum.com/t/actionmailer-views-confusion/169960>\
**Category:** Rails\
**Created:** [June 10, 2009, 6:47pm UTC](https://www.ruby-forum.com/t/actionmailer-views-confusion/169960 "2009-06-10T18:47:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![JannaB](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/df788c/32.png) [@JannaB](https://www.ruby-forum.com/u/JannaB)\
**Post date:** [June 10, 2009, 6:47pm UTC](https://www.ruby-forum.com/t/actionmailer-views-confusion/169960/1 "2009-06-10T18:47:32Z")

</div>

I have an ActionMailer, which has a corresponding controller (shown  
below). The form to create the email gets invoked from another form, a  
list of names and email addresses from another Model. I would like to  
return to this list after the mail is sent (for now, however, I am  
merely trying to return to Application.home() )

I have:

class EmailerController \< ApplicationController  
def sendmail  
recipient = params[:email][:recipient]  
subject = params[:email][:subject]  
message = params[:email][:message]  
returnadd = current\_associate.email  
mymail = Emailer.create\_contact(recipient, subject, message,  
returnadd)  
Emailer.deliver(mymail);

```
render :controller => 'application', :action => 'home'

```

end  
end

Nothing happens – nothing with the view changes after I click send on  
the form that feeds sendmail(), though the sendmail() gets executed  
and the mail properly sent. When I look into my logs, I see:

* * *

ActionView::MissingTemplate (Missing template emailer/list.erb in view  
path app/views):  
app/controllers/emailer\_controller.rb:11:in `sendmail’

## Rendering rescues/layout (internal\_server\_error)

But I do have an application controller and it does have a home  
method. Why does ActionMailer not forward onto there in my render  
command? How, typically, can I put the view back to what it WAS before  
the user elected to send an email ? -Janna B

---

<div class="post-metadata">

**Author:** ![JannaB](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/df788c/32.png) [@JannaB](https://www.ruby-forum.com/u/JannaB)\
**Post date:** [June 10, 2009, 7:25pm UTC](https://www.ruby-forum.com/t/actionmailer-views-confusion/169960/2 "2009-06-10T19:25:03Z")

</div>

On Jun 10, 5:46 pm, JannaB [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I have an ActionMailer, which has a corresponding controller (shown  
> below). The form to create the email gets invoked from another form, a  
> list of names and email addresses from another Model. I would like to  
> return to this list after the mail is sent (for now, however, I am  
> merely trying to return to Application.home() )

So do you actually want redirect\_to rather than render ?

Fred

---

<div class="post-metadata">

**Author:** ![JannaB](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/df788c/32.png) [@JannaB](https://www.ruby-forum.com/u/JannaB)\
**Post date:** [June 10, 2009, 8:40pm UTC](https://www.ruby-forum.com/t/actionmailer-views-confusion/169960/3 "2009-06-10T20:40:42Z")

</div>

Frederick

Either one – but niether get hit:

def sendmail  
recipient = params[:email][:recipient]  
subject = params[:email][:subject]  
message = params[:email][:message]  
returnadd = current\_associate.email  
puts “about to send”  
mymail = Emailer.create\_contact(recipient, subject, message,  
returnadd)  
Emailer.deliver(mymail);  
puts “sent!”  
redirect\_to :controller =\> ‘application’, :action =\>  
‘home’  
end

see, the “sent” is appearing…but nothing ever redirects! Any  
thoughts or suggestions here on this? Thanks! -Janna B

On Jun 10, 1:24 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![JannaB](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/df788c/32.png) [@JannaB](https://www.ruby-forum.com/u/JannaB)\
**Post date:** [June 12, 2009, 2:10pm UTC](https://www.ruby-forum.com/t/actionmailer-views-confusion/169960/4 "2009-06-12T14:10:08Z")

</div>

I’m trying to implement this on a Blackberry (whose support for  
Javascript is something of a joke, even when it is enabled) there has  
to be a proper way to redirect this in rails which does not involve  
javascript. It seems neither redirect\_to nor render get called  
(though, the puts line above it does, and the mail is correctly  
sent!).

So why can;t a redirect anywhere after this? -Janna B

---

<div class="post-metadata">

**Author:** ![JannaB](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/df788c/32.png) [@JannaB](https://www.ruby-forum.com/u/JannaB)\
**Post date:** [June 10, 2009, 9:22pm UTC](https://www.ruby-forum.com/t/actionmailer-views-confusion/169960/5 "2009-06-10T21:22:22Z")

</div>

Oh wait…it;s so easy…just close the div in javascript. Bingo!

---

<div class="post-metadata">

**Author:** ![JannaB](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/df788c/32.png) [@JannaB](https://www.ruby-forum.com/u/JannaB)\
**Post date:** [June 12, 2009, 8:12pm UTC](https://www.ruby-forum.com/t/actionmailer-views-confusion/169960/6 "2009-06-12T20:12:41Z")

</div>

According to the quoted exception the problem here is not the  
redirect. It is the actionmailer which doesnt find the template to  
render the email. This raises an exception and prevents further  
processing of your controller action. Name your email templates in the  
form name.text.plain.erb or name.text.html.erb depending on the mime  
type.

2009/6/12, JannaB [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> 

–  
Von meinen Mobilgerät aus gesendet
