Can Sessions work when Radiant is run from gem?

I’m trying to switch to running Radiant from the gem instead of a
full-source dump. Previously in order to use Sessions I had to
comment-out “session :off” in /app/controllers/admin/site_controller.rb.

The problem now is that when running from gem I don’t have access to the
app files and cannot make this edit. Is there any way I can override the
session global in the environment config or my extension code?

Thanks,

  • Dave

I should also note that previously I had caching turned off on the site,
and now I would like it turned on, since POST requests are no longer
cached by Radiant.

So…

Current => Radiant from full-source; No caching; Session turned on in
site_controller.rb

Desired => Radiant from gem; Full caching; Session turned on in config
or extension

David P. wrote:

Current => Radiant from full-source; No caching; Session turned on in
site_controller.rb

Desired => Radiant from gem; Full caching; Session turned on in config
or extension

You should be able to make an extension that does this. The activate and
deactivate methods would look something like this:

def activate
SiteController.class_eval { session :on }
end

def deactivate
SiteController.class_eval { session :off }
end


John L.
http://wiseheartdesign.com

Yet again John beats me to the punch and says the same thing I was going
to! :wink:

You might also want to make sure that this line is at the top of your
extension file:

require_dependency ‘application’

Sean

Sean C. wrote:

You might also want to make sure that this line is at the top of your
extension file:

require_dependency ‘application’

This fixed the error, but sessions don’t seem to be holding…

John W. Long wrote:

You should be able to make an extension that does this. The activate and
deactivate methods would look something like this:

def activate
SiteController.class_eval { session :on }
end

def deactivate
SiteController.class_eval { session :off }
end

class MemberLoginExtension < Radiant::Extension
version “1.0”
description “Adds tags to allow for member logins.”
url “”

def activate
Page.class_eval { include MemberLogin }
SiteController.class_eval { session :on }
end

def deactivate
SiteController.class_eval { session :off }
end
end

… This is generating the following error, which I’m guessing is
because SiteController is not in MemberLoginExtension’s scope…

** Starting Mongrel listening at 0.0.0.0:3000
** Starting Rails with development environment…
Exiting
/usr/local/lib/ruby/gems/1.8/gems/radiant-0.6.2/vendor/rails/activesupport/lib/active_support/dependencies.rb:266:in
load_missing_constant': uninitialized constant ApplicationController (NameError) from /usr/local/lib/ruby/gems/1.8/gems/radiant-0.6.2/vendor/rails/activesupport/lib/active_support/dependencies.rb:452:inconst_missing’
from
/usr/local/lib/ruby/gems/1.8/gems/radiant-0.6.2/vendor/rails/activesupport/lib/active_support/dependencies.rb:464:in
const_missing' from /usr/local/lib/ruby/gems/1.8/gems/radiant-0.6.2/app/controllers/site_controller.rb:1 from /usr/local/lib/ruby/gems/1.8/gems/radiant-0.6.2/vendor/rails/activesupport/lib/active_support/dependencies.rb:203:inload_without_new_constant_marking’
from
/usr/local/lib/ruby/gems/1.8/gems/radiant-0.6.2/vendor/rails/activesupport/lib/active_support/dependencies.rb:203:in
load_file' from /usr/local/lib/ruby/gems/1.8/gems/radiant-0.6.2/vendor/rails/activesupport/lib/active_support/dependencies.rb:342:innew_constants_in’
from
/usr/local/lib/ruby/gems/1.8/gems/radiant-0.6.2/vendor/rails/activesupport/lib/active_support/dependencies.rb:202:in
load_file' from /usr/local/lib/ruby/gems/1.8/gems/radiant-0.6.2/vendor/rails/activesupport/lib/active_support/dependencies.rb:94:inrequire_or_load’
… 45 levels…
from
/usr/local/lib/ruby/gems/1.8/gems/radiant-0.6.2/vendor/rails/railties/lib/commands/server.rb:39
from
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
gem_original_require' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:inrequire’
from script/server:3

require_dependency ‘application’ should fix that issue. This is
something that has bugged me about Rails for a long time…
ApplicationController’s file is ‘application.rb’ and not
‘application_controller.rb’.

Sean

Wait, why would “cache_page? false” prevent page caching if this is a
module and not a controller? I don’t think my logic makes sense…

David P. wrote:

This fixed the error, but sessions don’t seem to be holding…

It looks like the non-logged-in version of the page is being cached,
despite the fact that I have the following:

module MemberLogin

include Radiant::Taggable

def cache_page?
false
end

end

David,

Radiant uses its own custom caching. Traditional Rails caching
mechanisms do not apply. However, rather than including the module
directly into Page, you may want to create a special page type for
member-restricted pages that prevents caching. I also believe it’s
‘cache?’ and not ‘cache_page?’. The latter was used in behaviors, pre
0.6.0.

Sean

Sean C. wrote:

However, rather than including the module
directly into Page, you may want to create a special page type for
member-restricted pages that prevents caching.

Thanks for the help Sean. I’ll look into this method of doing things. It
may be another ten days until I get back to this project, though…
ugh…

Unfortunately, session :on does not enable session.
That’s the way it has been implemented in rails.

This patch tries to
make session management intutive.

John W. Long wrote:

David P. wrote:

Current => Radiant from full-source; No caching; Session turned on in
site_controller.rb

Desired => Radiant from gem; Full caching; Session turned on in config
or extension

You should be able to make an extension that does this. The activate and
deactivate methods would look something like this:

def activate
SiteController.class_eval { session :on }
end

def deactivate
SiteController.class_eval { session :off }
end


John L.
http://wiseheartdesign.com