# Not able to access session data in before\_filter

**URL:** <https://www.ruby-forum.com/t/not-able-to-access-session-data-in-before-filter/159840>\
**Category:** Ruby\
**Created:** [February 9, 2009, 10:41am UTC](https://www.ruby-forum.com/t/not-able-to-access-session-data-in-before-filter/159840 "2009-02-09T10:41:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![preethi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f04885/32.png) [@preethi](https://www.ruby-forum.com/u/preethi)\
**Post date:** [February 9, 2009, 10:41am UTC](https://www.ruby-forum.com/t/not-able-to-access-session-data-in-before-filter/159840/1 "2009-02-09T10:41:58Z")

</div>

Hi,

I’ve a session data that is generated when a user logs in.  
I’m trying to access that session data, in before\_filter, in a different  
controller for passing parameter to the before\_filter function.

before\_filter :only =\> [:index] do |obj|  
user = session[:user]  
has\_permission\_in\_any(user.id,component\_id,permission\_id,user.communities)  
end

But i’m not able to do that. What might be the reason?

---

<div class="post-metadata">

**Author:** ![preethi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f04885/32.png) [@preethi](https://www.ruby-forum.com/u/preethi)\
**Post date:** [February 9, 2009, 12:09pm UTC](https://www.ruby-forum.com/t/not-able-to-access-session-data-in-before-filter/159840/2 "2009-02-09T12:09:10Z")

</div>

Preethi S. wrote:

> Hi,
> 
> I’ve a session data that is generated when a user logs in.  
> I’m trying to access that session data, in before\_filter, in a different  
> controller for passing parameter to the before\_filter function.
> 
> before\_filter :only =\> [:index] do |obj|  
> user = session[:user]  
> has\_permission\_in\_any(user.id,component\_id,permission\_id,user.communities)  
> end
> 
> But i’m not able to do that. What might be the reason?

As a guess, because you didn’t actually say so, you’re asking about the  
Rails web application framework.

You’d best ask this question on a Rails mailing list. Here you’ve found  
the list for the Ruby programming language (which Rails just happens to  
be written in).

---

<div class="post-metadata">

**Author:** ![preethi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f04885/32.png) [@preethi](https://www.ruby-forum.com/u/preethi)\
**Post date:** [February 9, 2009, 12:32pm UTC](https://www.ruby-forum.com/t/not-able-to-access-session-data-in-before-filter/159840/3 "2009-02-09T12:32:14Z")

</div>

Brian C. wrote:

> Preethi S. wrote:
> 
> > Hi,
> > 
> > I’ve a session data that is generated when a user logs in.  
> > I’m trying to access that session data, in before\_filter, in a different  
> > controller for passing parameter to the before\_filter function.
> > 
> > before\_filter :only =\> [:index] do |obj|  
> > user = session[:user]  
> > has\_permission\_in\_any(user.id,component\_id,permission\_id,user.communities)  
> > end
> > 
> > But i’m not able to do that. What might be the reason?
> 
> As a guess, because you didn’t actually say so, you’re asking about the  
> Rails web application framework.
> 
> You’d best ask this question on a Rails mailing list. Here you’ve found  
> the list for the Ruby programming language (which Rails just happens to  
> be written in).

thanks for guiding me to the right path 🙂
