# Url (view \> controller) error "Need controller and action!"

**URL:** <https://www.ruby-forum.com/t/url-view-controller-error-need-controller-and-action/164621>\
**Category:** Rails\
**Created:** [April 3, 2009, 9:52am UTC](https://www.ruby-forum.com/t/url-view-controller-error-need-controller-and-action/164621 "2009-04-03T09:52:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![zambezi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/eada6e/32.png) [@zambezi](https://www.ruby-forum.com/u/zambezi)\
**Post date:** [April 3, 2009, 9:52am UTC](https://www.ruby-forum.com/t/url-view-controller-error-need-controller-and-action/164621/1 "2009-04-03T09:52:26Z")

</div>

I thought I would set up a simple form for email noification to tinker  
with and see how it worked However the simplicity part has so far  
eluded me. Currently this particular page generates an error “Need  
controller and action!” when to my eyes everything is in order.

Any suggestions as to what is going on. Thanks in advance.  
Bill

ERROR  
ActionController::RoutingError in Emailer#send\_mail

Showing emailer/display.html.erb where line #71 raised:

Need controller and action!

## Extracted source (around line #71): 71: \<% form\_for(:emailer, :url =\> {:action =\> ‘send\_mail’}, :html =\> {:class =\> ‘style1’}) do |f| %\>

FORM  
\<% form\_for(:emailer, :url =\> {:action =\> ‘send\_mail’}, :html =\>  
{:class =\> ‘style1’}) do |f| %\>  
\<%= label(:subject, ‘Topic:’) %\>  
\<%= f.select :subject, %w{ Hyponatremia/hydration Admin/  
site }%\>  
  
\<%= label(:comment, ‘Comments:’) %\>  
\<%= f.text\_area :comment, :cols =\> 40, :rows =\> 10 %\>   
  
\<%= label(:from, ‘Name:’) %\>  
\<%= f.text\_field :from, :style =\> “width: 200px;” %\>  
  
\<%= label(:senderemail, ‘Email:’) %\>  
\<%= f.text\_field :senderemail, :style =\> “width: 200px;”  
%\>  
  
\<%= submit\_tag ‘Send’ %\>

* * *

CONTROLLER  
class EmailerController \< ApplicationController  
def display  
render :action =\> ‘display’  
end

```
def send_mail
    Emailer.deliver_display

```

(:subject, :comment, :senderemail, :from)  
end  
end

---

<div class="post-metadata">

**Author:** ![zambezi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/eada6e/32.png) [@zambezi](https://www.ruby-forum.com/u/zambezi)\
**Post date:** [April 3, 2009, 10:04am UTC](https://www.ruby-forum.com/t/url-view-controller-error-need-controller-and-action/164621/2 "2009-04-03T10:04:10Z")

</div>

On Apr 3, 3:19 am, zambezi [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I thought I would set up a simple form for email noification to tinker  
> with and see how it worked However the simplicity part has so far  
> eluded me. Currently this particular page generates an error “Need  
> controller and action!” when to my eyes everything is in order.

The clue should be in the message - you’re not supplying a  
controller 🙂  
Normally if you don’t supply the :controller option then the current  
one is implicit, but things are different when rendering an email.

Fred

---

<div class="post-metadata">

**Author:** ![zambezi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/eada6e/32.png) [@zambezi](https://www.ruby-forum.com/u/zambezi)\
**Post date:** [April 3, 2009, 11:14pm UTC](https://www.ruby-forum.com/t/url-view-controller-error-need-controller-and-action/164621/3 "2009-04-03T23:14:41Z")

</div>

Thank you, Fred. You were spot on. Explicitly designating the  
controller resolved the error.

However that brought me to the next error/issue:

NoMethodError in Emailer#send\_mail  
Showing emailer/display.html.erb where line #71 raised:

undefined method `protect\_against\_forgery?’ for #\<ActionView::Base:  
0x34d9c68\>

Extracted source (around line #71):  
71: \<% form\_for(:emailer, :url =\> {:controller =\> ‘emailer’, :action  
=\> ‘send\_mail’}, :html =\> {:class =\> ‘style1’}) do |f| %\>

RAILS\_ROOT: C:/RubyRails/rails\_apps/rappEAHv2  
Application Trace | Framework Trace | Full Trace

C:/RubyRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/  
action\_view/helpers/form\_tag\_helper.rb:404:in `extra_tags_for_form' C:/RubyRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/ action_view/helpers/form_tag_helper.rb:412:in `form\_tag\_html’  
C:/RubyRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/  
action\_view/helpers/form\_tag\_helper.rb:41:in `form_tag' C:/RubyRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/ action_view/helpers/form_helper.rb:183:in `form\_for’  
app/views/emailer/display.html.erb:71:in  
`_run_erb_47app47views47emailer47display46html46erb' app/controllers/emailer_controller.rb:8:in `send\_mail’  
-e:3:in `load’  
-e:3

* * *

Googling on the error didn’t turn up much and generally seemed to  
attribute the problem to weirdness. One suggestion was that the  
problem’s roots were due to plugin installation. But I haven’t  
tinkered with the default installation plugins . Another suggestion  
was to create a new project and try again. I did and the issue  
persisted.

There were a couple of suggestions to disable or dodge  
protect\_against\_forgery. I was unable to do so via the controller,  
but adding the following in the helper class punted the issue down the  
field.

```
def protect_against_forgery?
    false
end

```

* * *

The punt didn’t go far. This “fix” perhaps not unexpectedly resulted  
in the next error: “ActionController::InvalidAuthenticityToken”.

Sooo, I’m at the deep end of the pool here. I really didn’t want to  
learn all about authenticity tokens at this stage of my learning  
ruby. Any further suggestions will be much appreciated as to how to  
get past this error.

Thanks, Bill

On Apr 3, 3:02 am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![zambezi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/eada6e/32.png) [@zambezi](https://www.ruby-forum.com/u/zambezi)\
**Post date:** [April 4, 2009, 12:44am UTC](https://www.ruby-forum.com/t/url-view-controller-error-need-controller-and-action/164621/4 "2009-04-04T00:44:50Z")

</div>

On Apr 3, 10:13 pm, zambezi [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> The punt didn’t go far. This “fix” perhaps not unexpectedly resulted  
> in the next error: “ActionController::InvalidAuthenticityToken”.
> 
> Sooo, I’m at the deep end of the pool here. I really didn’t want to  
> learn all about authenticity tokens at this stage of my learning  
> ruby. Any further suggestions will be much appreciated as to how to  
> get past this error.

Very short version: to protect against CSRF attacks, forms generated  
by rails have a hidden input with a magic token. Together with the  
session this helps verify that a request isn’t been faked by a CSRF  
attack. With the protect\_against\_forgery returning false thing you’ve  
stopped your form trying to make such a token, but you still need to  
make the other end not expect a token. One way is to make your form  
use the GET method, another is to skip the verify\_authenticity\_token  
filter in the appropriate controller.

Fred

---

<div class="post-metadata">

**Author:** ![zambezi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/eada6e/32.png) [@zambezi](https://www.ruby-forum.com/u/zambezi)\
**Post date:** [April 6, 2009, 9:40pm UTC](https://www.ruby-forum.com/t/url-view-controller-error-need-controller-and-action/164621/5 "2009-04-06T21:40:59Z")

</div>

Hello Fred,

With Ruby and Rails a whole new experience its sometimes difficult to  
even frame a coherent question. So thank you your answers and for  
going a step further and adding some very helpful explanation. It  
clarified my thinking

Since I don’t want to operate without protect\_against\_forgery and  
implementing a workaround isn’t where I need to be spending time now,  
I searched about and came across some exmaples of a ‘tableless’  
arrangement that implemented well with some minor modification.

Thanks again.  
Bill

On Apr 3, 5:43 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
