# Retrieve session\_key

**URL:** <https://www.ruby-forum.com/t/retrieve-session-key/88632>\
**Category:** Rails\
**Created:** [March 13, 2007, 6:31am UTC](https://www.ruby-forum.com/t/retrieve-session-key/88632 "2007-03-13T06:31:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![monki](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f07891/32.png) [@monki](https://www.ruby-forum.com/u/monki)\
**Post date:** [March 13, 2007, 6:31am UTC](https://www.ruby-forum.com/t/retrieve-session-key/88632/1 "2007-03-13T06:31:14Z")

</div>

The unobtrusive javascript plugin stores its generate javascript files  
in the session.  
But it has some issues currently putting things into the wrong session  
(because it doesn’t check to see what session key is being set in the  
application controller). As such, it doesn’t work unless you  
explicitly set the session key.

Currently I just added a line to my application controller like so:  
UnobtrusiveJavascriptController.send :session, :session\_key =\>  
‘\_reminders\_session\_id’

I’d like to fix the UJS plugin and submit a patch, but I’m not sure  
how to best go about it.

You can’t simply change the UnobtrusiveJavascriptController to derive  
from ApplicationController because it won’t know what it is when it  
loads. So possibly you could do this, but specify a dependency or  
order of loading?

Otherwise within the UJS controller you could set the session key to  
match the application. The only way I have been able to get this to  
work is the following:  
session :session\_key =\>  
ApplicationController.session.first[:session\_key]

But this seems fragile and inelegant to say the least.

Comments, suggestions?
