# Sessions in Radiant Help

**URL:** <https://www.ruby-forum.com/t/sessions-in-radiant-help/120459>\
**Category:** Radiant CMS\
**Created:** [November 17, 2007, 3:51am UTC](https://www.ruby-forum.com/t/sessions-in-radiant-help/120459 "2007-11-17T03:51:25Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![maged](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/51bf81/32.png) [@maged](https://www.ruby-forum.com/u/maged)\
**Post date:** [November 17, 2007, 3:51am UTC](https://www.ruby-forum.com/t/sessions-in-radiant-help/120459/1 "2007-11-17T03:51:25Z")

</div>

Hey all,  
I know this discussion has taken place before but I still can’t  
get my hands around it. I’m using radiant with the Rails\_support  
extension which works great with radiant for the content. The problem is  
when I try to use the session inside that app in the extensions, The  
session doesn’t hold any data. The session that comes with radiant only  
get stuff written to it when I try to access the radiant admin app.

Does any one have a solution for that or even a way around it. I really  
appreciate the help.

Thanks

Maged

---

<div class="post-metadata">

**Author:** ![maged](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/51bf81/32.png) [@maged](https://www.ruby-forum.com/u/maged)\
**Post date:** [November 17, 2007, 4:31am UTC](https://www.ruby-forum.com/t/sessions-in-radiant-help/120459/2 "2007-11-17T04:31:19Z")

</div>

Jeff Dean wrote:

> I believe that this is because of a bug in rails, and not radiant.  
> The SiteController has session :off, and adding session :on in your  
> controllers doesn’t seem to do anything.
> 
> The only way I know to change this is to actually go into  
> SiteController and comment out that line. I’ve seen posts about  
> putting things like:
> 
> SiteController.class\_eval{session :on}
> 
> in the activate method of your extension, but that didn’t work for me.
> 
> To get it to work, I did froze to edge radiant, then went into  
> SiteController.rb and commented out the session line. This would mean  
> that any pages that you want sessions off for you’d have to do  
> manually - so use with caution.
> 
> Jeff

Thanks for your help. Could you explain your last paragraph in more  
details, I’m totally new to Radiant. where can I find the  
SiteController.rb? any examples would be very helpful

My extension rails\_support\_extension.rb looks like this

\*\*  
require\_dependency ‘application’

class RailsSupportExtension \< Radiant::Extension  
version “1.0”  
description "Allows you to render Rails views in Radiant Layouts. "  
url “[Google Code Archive - Long-term storage for Google Code Project Hosting.](http://code.google.com/p/radiant-rails-support/)”

def activate  
end

def deactivate  
end

SiteController.send :include, SiteControllerExtension  
SiteController.helper SiteHelperExtension

end  
\*\*

Thanks in advance  
Maged M.

---

<div class="post-metadata">

**Author:** ![maged](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/51bf81/32.png) [@maged](https://www.ruby-forum.com/u/maged)\
**Post date:** [November 17, 2007, 4:04am UTC](https://www.ruby-forum.com/t/sessions-in-radiant-help/120459/3 "2007-11-17T04:04:04Z")

</div>

I believe that this is because of a bug in rails, and not radiant.  
The SiteController has session :off, and adding session :on in your  
controllers doesn’t seem to do anything.

The only way I know to change this is to actually go into  
SiteController and comment out that line. I’ve seen posts about  
putting things like:

SiteController.class\_eval{session :on}

in the activate method of your extension, but that didn’t work for me.

To get it to work, I did froze to edge radiant, then went into  
SiteController.rb and commented out the session line. This would mean  
that any pages that you want sessions off for you’d have to do  
manually - so use with caution.

Jeff

---

<div class="post-metadata">

**Author:** ![maged](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/51bf81/32.png) [@maged](https://www.ruby-forum.com/u/maged)\
**Post date:** [November 17, 2007, 4:50am UTC](https://www.ruby-forum.com/t/sessions-in-radiant-help/120459/4 "2007-11-17T04:50:29Z")

</div>

Here’s what I did:

gem install --include-dependencies radiant  
radiant myapp  
cd myapp  
[change database.yml]  
rake db:bootstrap  
rake radiant:freeze:edge  
rake radiant:update  
rake db:migrate  
[create extension…]

Now you’ll have a full copy of radiant’s source code in your vendor/  
radiant directory. Now go to

vendor/radiant/app/controllers

You’ll see site\_controller.rb (which I mistakenly referred to as  
SiteController.rb below) - comment out line 2, and sessions will now  
be enabled for the whole app. If you’ve previously started your web  
server, you may have to restart for the changes to take effect.

There are much more elegant solutions, I’m sure, but this one worked  
for me. If you have a problem with edge radiant this might not work.  
If that happens, let me know.

---

<div class="post-metadata">

**Author:** ![maged](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/51bf81/32.png) [@maged](https://www.ruby-forum.com/u/maged)\
**Post date:** [November 17, 2007, 7:12am UTC](https://www.ruby-forum.com/t/sessions-in-radiant-help/120459/5 "2007-11-17T07:12:50Z")

</div>

I haven’t dealt with that before, but if I were to do it, I would:  
Determine what I meant by expired (let’s say 3 days for example)  
Write a rake task that deletes the session  
Write a cron script to run it nightly after the database backup

My rake task would probably look like:

namespace :db  
namespace :sessions  
task :delete =\> :environment do

CGI::Session::ActiveRecordStore::Session.delete\_all([‘created\_at \< ?’,  
3.days.ago])  
end  
end  
end

My cron script would look something like this:

mkdir -p /var/backup/mysql  
date=`date "+%d"`  
mysqldump -ubackup -pmypass myapp\_production | gzip \> /var/backup/  
mysql/myapp-$date.sql.gz  
cd /var/www/apps/myapp/current && rake db:sessions:delete

Alternately, you could have it run every time an admin logs in  
(assuming that your admins don’t mind the slight performance hit)

Jeff

---

<div class="post-metadata">

**Author:** ![maged](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/51bf81/32.png) [@maged](https://www.ruby-forum.com/u/maged)\
**Post date:** [November 17, 2007, 5:54am UTC](https://www.ruby-forum.com/t/sessions-in-radiant-help/120459/6 "2007-11-17T05:54:31Z")

</div>

Jeff Dean wrote:

> Here’s what I did:
> 
> gem install --include-dependencies radiant  
> radiant myapp  
> cd myapp  
> [change database.yml]  
> rake db:bootstrap  
> rake radiant:freeze:edge  
> rake radiant:update  
> rake db:migrate  
> [create extension…]
> 
> Now you’ll have a full copy of radiant’s source code in your vendor/  
> radiant directory. Now go to
> 
> vendor/radiant/app/controllers
> 
> You’ll see site\_controller.rb (which I mistakenly referred to as  
> SiteController.rb below) - comment out line 2, and sessions will now  
> be enabled for the whole app. If you’ve previously started your web  
> server, you may have to restart for the changes to take effect.
> 
> There are much more elegant solutions, I’m sure, but this one worked  
> for me. If you have a problem with edge radiant this might not work.  
> If that happens, let me know.

Hey Jeff,  
Thanks a lot man, I tried it and it works perfectly. Just one  
more question. Do you know how to delete that session from the database  
when the session expired. I read some posts and they talked cron jobs  
and things like that but I needed to be handled in my application. Do  
you have a quick solution?

I really appreciate your help man

Maged

---

<div class="post-metadata">

**Author:** ![maged](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/51bf81/32.png) [@maged](https://www.ruby-forum.com/u/maged)\
**Post date:** [November 17, 2007, 11:04am UTC](https://www.ruby-forum.com/t/sessions-in-radiant-help/120459/7 "2007-11-17T11:04:28Z")

</div>

You can enable sessions for a particular extension by doing something  
like this:

class YourExtension \< Radiant::Extension  
def activate  
YourController.class\_eval { session :disabled =\> false }  
end  
end

This works on Radiant 6.0.3. I found this on the mailing list. I do not  
think this is documented.

Regards,  
Erik.

Jeff Dean wrote:

> in the activate method of your extension, but that didn’t work for me.
> 
> To get it to work, I did froze to edge radiant, then went into  
> SiteController.rb and commented out the session line. This would mean  
> that any pages that you want sessions off for you’d have to do  
> manually - so use with caution.
> 
> Jeff

–  
Erik van Oosten  
[http://2008.rubyenrails.nl/](http://2008.rubyenrails.nl/)

> **[Day to day stuff](http://day-to-day-stuff.blogspot.com/)**
>
> Experiences from a hard core JVM programmer. Likes to keep things simple.

---

<div class="post-metadata">

**Author:** ![maged](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/51bf81/32.png) [@maged](https://www.ruby-forum.com/u/maged)\
**Post date:** [November 19, 2007, 2:28pm UTC](https://www.ruby-forum.com/t/sessions-in-radiant-help/120459/8 "2007-11-19T14:28:20Z")

</div>

But this shouldn’t work because the method session is undefined for  
yourextension\_extension.rb.

That’s the error I get when I try to do what you said:  
in `activate': undefined method`session’ for SolrTags:Module  
(NoMethodError)

But I’m using radiant 6.0.4 so could be this. How could I get the method  
session for my \_extension.rb file?

Marc
