# Session based Routing

**URL:** <https://www.ruby-forum.com/t/session-based-routing/183305>\
**Category:** Rails\
**Created:** [February 11, 2010, 2:24pm UTC](https://www.ruby-forum.com/t/session-based-routing/183305 "2010-02-11T14:24:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![LeonS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/c77e96/32.png) [@LeonS](https://www.ruby-forum.com/u/LeonS)\
**Post date:** [February 11, 2010, 2:24pm UTC](https://www.ruby-forum.com/t/session-based-routing/183305/1 "2010-02-11T14:24:39Z")

</div>

Hi,

I’m developing a site with a Login on the frontpage, so when you  
logged in you will see  
another “thing” than if you are not logged in.  
For Example you will see some explanations about the site if you are a  
visitor, but if you are logged in  
you will some things specific for you and i want to show that on the  
frontpage e.g. [example.com](http://example.com).  
How can I handle that? I’m using Authlogic für Session handling and  
Login.  
My Idea is a session based Routing, but I don’t know how that can be  
done?

greetings

---

<div class="post-metadata">

**Author:** ![LeonS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/c77e96/32.png) [@LeonS](https://www.ruby-forum.com/u/LeonS)\
**Post date:** [February 11, 2010, 2:28pm UTC](https://www.ruby-forum.com/t/session-based-routing/183305/2 "2010-02-11T14:28:44Z")

</div>

On Thu, Feb 11, 2010 at 08:23, LeonS [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Login.

As far as I know, that’s not possible. One option would be for the  
controller receiving that action to render entirely different  
templates based on whether the user is logged in:

class HomeController  
def show  
if current\_user  
render :action =\> ‘show\_logged\_in’  
else  
render :action =\> ‘show’  
end  
end  
end

Note that the ‘show\_logged\_in’ action doesn’t actually need to exist;  
the name of the option is a bit misleading here.  
Note also that the “else” statement isn’t necessary; I just included  
it here for clarity.

Mat

---

<div class="post-metadata">

**Author:** ![LeonS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/c77e96/32.png) [@LeonS](https://www.ruby-forum.com/u/LeonS)\
**Post date:** [February 11, 2010, 5:59pm UTC](https://www.ruby-forum.com/t/session-based-routing/183305/3 "2010-02-11T17:59:29Z")

</div>

On Thu, Feb 11, 2010 at 7:23 AM, LeonS [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> I’m developing a site with a Login on the frontpage, so when you  
> logged in you will see  
> another “thing” than if you are not logged in.

Something like:

\<%= render partial =\> session[:user\_id] ? ‘logged\_in’ : ‘something\_else’  
%\>

–  
Greg D.  
[destiney.com](http://destiney.com) | [gregdonald.com](http://gregdonald.com)

---

<div class="post-metadata">

**Author:** ![LeonS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/c77e96/32.png) [@LeonS](https://www.ruby-forum.com/u/LeonS)\
**Post date:** [February 11, 2010, 7:26pm UTC](https://www.ruby-forum.com/t/session-based-routing/183305/4 "2010-02-11T19:26:08Z")

</div>

On Thu, Feb 11, 2010 at 11:56 AM, Greg D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On Thu, Feb 11, 2010 at 7:23 AM, LeonS [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > I’m developing a site with a Login on the frontpage, so when you  
> > logged in you will see  
> > another “thing” than if you are not logged in.
> 
> Something like:
> 
> \<%= render partial =\> session[:user\_id] ? ‘logged\_in’ : ‘something\_else’ %\>

The normal way to do this is to handle it at the controller level in a  
before filter set in the ApplicationController, used to check that the  
user is logged in, via the session, and/or a token, and or via basic  
http authentication depending on the requirements of the application,  
and redirects to the login url if not.

–  
Rick DeNatale

Blog: [http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)  
Twitter: [http://twitter.com/RickDeNatale](http://twitter.com/RickDeNatale)  
WWR: [http://www.workingwithrails.com/person/9021-rick-denatale](http://www.workingwithrails.com/person/9021-rick-denatale)  
LinkedIn: [Rick DeNatale - Developer - IBM | LinkedIn](http://www.linkedin.com/in/rickdenatale)

---

<div class="post-metadata">

**Author:** ![LeonS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/c77e96/32.png) [@LeonS](https://www.ruby-forum.com/u/LeonS)\
**Post date:** [February 12, 2010, 2:11pm UTC](https://www.ruby-forum.com/t/session-based-routing/183305/5 "2010-02-12T14:11:43Z")

</div>

On Fri, Feb 12, 2010 at 08:03, LeonS [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > > On Thu, Feb 11, 2010 at 7:23 AM, LeonS [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:  
> > > user is logged in, via thesession, and/or a token, and or via basic
> 
> –  
> You received this message because you are subscribed to the Google G. “Ruby on Rails: Talk” group.  
> To post to this group, send email to removed\_email\_address@domain.invalid.  
> To unsubscribe from this group, send email to removed\_email\_address@domain.invalid.  
> For more options, visit this group at [http://groups.google.com/group/rubyonrails-talk?hl=en](http://groups.google.com/group/rubyonrails-talk?hl=en).

Same action, different views.

---

<div class="post-metadata">

**Author:** ![LeonS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/c77e96/32.png) [@LeonS](https://www.ruby-forum.com/u/LeonS)\
**Post date:** [February 12, 2010, 2:04pm UTC](https://www.ruby-forum.com/t/session-based-routing/183305/6 "2010-02-12T14:04:41Z")

</div>

And how does twitter is doing that?  
There is no Redirect to something, when i visit the Root URL As  
a visitor and with à Session the Main Page is my tweetlist.
