# Form\_for - over riding the controller that generates the for

**URL:** <https://www.ruby-forum.com/t/form-for-over-riding-the-controller-that-generates-the-for/110844>\
**Category:** Rails\
**Created:** [July 31, 2007, 2:21pm UTC](https://www.ruby-forum.com/t/form-for-over-riding-the-controller-that-generates-the-for/110844 "2007-07-31T14:21:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mindtonic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f19dbf/32.png) [@mindtonic](https://www.ruby-forum.com/u/mindtonic)\
**Post date:** [July 31, 2007, 2:21pm UTC](https://www.ruby-forum.com/t/form-for-over-riding-the-controller-that-generates-the-for/110844/1 "2007-07-31T14:21:31Z")

</div>

Hello,

I am trying to install my login and search forms as default parts of  
the layout. This is the code I am using:

\<% form\_for :user, :url =\> {:action =\> ‘authenticate’} do |f| %\>

Username:  
\<%= f.text\_field :username, :size =\> 30 %\>

Password:  
\<%= f.password\_field :password, :size =\> 30 %\>

 \<%= submit\_tag 'Login' %\> \<% end %\>

This is the form that is created:

LOGIN PASSWORD

The form action is referring to the pages controller. I need it to  
refer to the accounts controller, which the same code does after  
whenever permissions are not granted. How can I tell form\_for which  
specific controller to reference?

Thanks!

---

<div class="post-metadata">

**Author:** ![mindtonic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f19dbf/32.png) [@mindtonic](https://www.ruby-forum.com/u/mindtonic)\
**Post date:** [July 31, 2007, 2:32pm UTC](https://www.ruby-forum.com/t/form-for-over-riding-the-controller-that-generates-the-for/110844/2 "2007-07-31T14:32:33Z")

</div>

The answer turns out to be quite simple:

form\_for :user, :url =\> {:action =\> ‘authenticate’, :controller =\>  
‘account’ }

\<% form\_for :user, :url =\> {:action =\> ‘authenticate’, :controller =\>  
‘account’ } do |f| %\>

Username:  
\<%= f.text\_field :username, :size =\> 30 %\>\</  
p\>

Password:  
\<%= f.password\_field :password, :size =\> 30  
%\>

  
\<%= submit\_tag ‘Login’ %\>  
\<% end %\>
