# A global login form that works from ANY page

**URL:** <https://www.ruby-forum.com/t/a-global-login-form-that-works-from-any-page/120462>\
**Category:** Rails\
**Created:** [November 17, 2007, 5:24am UTC](https://www.ruby-forum.com/t/a-global-login-form-that-works-from-any-page/120462 "2007-11-17T05:24:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![steveoco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/db5fbb/32.png) [@steveoco](https://www.ruby-forum.com/u/steveoco)\
**Post date:** [November 17, 2007, 5:24am UTC](https://www.ruby-forum.com/t/a-global-login-form-that-works-from-any-page/120462/1 "2007-11-17T05:24:52Z")

</div>

Hello,

I seem to be having a very hard time creating a login form that would  
sit in the sidebar or header of a website which can be used to login  
from ANY page.

The problem is that the login form needs to be somehow ‘included’ in the  
application ‘global’ layout, but all the reference material places the  
“login” method as a separate view.

How would I include the login as part of the layout?

---

<div class="post-metadata">

**Author:** ![steveoco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/db5fbb/32.png) [@steveoco](https://www.ruby-forum.com/u/steveoco)\
**Post date:** [November 17, 2007, 7:00am UTC](https://www.ruby-forum.com/t/a-global-login-form-that-works-from-any-page/120462/2 "2007-11-17T07:00:31Z")

</div>

Steve,

You reference a partial in your master layout file, application.rhtml  
which resides in views/layouts. You will need to include the path to  
the partial though.

For example, if you have a login form in apps/views/sessions/  
\_form.rhtml

then you could reference that in your application.rhtml file as:

\<%= render :partial =\> ‘sessions/\_form.html’ %\>

Cheers,  
Nicholas

On Nov 16, 11:24 pm, Steve O. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![steveoco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/db5fbb/32.png) [@steveoco](https://www.ruby-forum.com/u/steveoco)\
**Post date:** [November 17, 2007, 10:20pm UTC](https://www.ruby-forum.com/t/a-global-login-form-that-works-from-any-page/120462/3 "2007-11-17T22:20:23Z")

</div>

On Nov 16, 2007, at 10:24 PM, Steve O. wrote:

> I seem to be having a very hard time creating a login form that would  
> sit in the sidebar or header of a website which can be used to login  
> from ANY page.
> 
> The problem is that the login form needs to be somehow ‘included’ in  
> the  
> application ‘global’ layout, but all the reference material places the  
> “login” method as a separate view.
> 
> How would I include the login as part of the layout?

Here’s how I do it:

In my views directory I created a directory called shared, where I put  
any partials that are used in more than one place.  
In there I have a partial named \_quick\_login\_form.rhtml that creates  
the form fields.  
Then in my layout I have this:

\<% form\_tag :action =\> 'login', :controller =\> :login do %\> \<%= render :partial =\> '/shared/quick\_login\_form' %\> \<%= submit\_tag "Member Login" %\>  
\<%= link\_to "Forgot your Login?", :action =\> :forgotten\_login, :controller =\> :login %\> \<% end %\>

You could put the whole form in the partial, of course.
