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.
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
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.
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.
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
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?
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.