Cookie based session management problems

Edge has a change in default behaviour where sessions are stored as
cookies instead of in the file system. This was a pleasant surprise when
I synced up, fired up my app, and nothing worked. Ah, life on the edge.

I’m sure I’m just missing something, but I can’t get sessions to survive
the first redirect. I added the following code to environment.rb, based
on Ryan’s (http://www.ryandaigle.com/) note:

config.action_controller.session = {
:session_key => ‘_<%= app_name %>_session’,
:secret => ‘<%= CGI::Session.generate_unique_id(app_name) %>’
}

The problem is probably related to the fact that the embedded ruby is
not getting processed. The generated cookie is

NAME: _<%
VALUE app_name %>_session…

What am I missing? (I’m in dev mode, btw).

TIA,
Keith

On 3/1/07, Keith L. [email protected] wrote:

:session_key => ‘_<%= app_name %>_session’,
:secret => ‘<%= CGI::Session.generate_unique_id(app_name) %>’
}

The problem is probably related to the fact that the embedded ruby is
not getting processed. The generated cookie is

NAME: _<%
VALUE app_name %>_session…

What am I missing? (I’m in dev mode, btw).

<% %> is used for erb. However, since config files use ruby, you’ll
have to use #{} for variables.

The reason Ryan’s sample has that is because he’s taking code from the
rails app generator. Once generated with a command like ‘rails foo’,
your app will have this:

config.action_controller.session = {
:session_key => ‘foo_session’,
:secret => ‘someuniquehash’
}


Rick O.
http://weblog.techno-weenie.net
http://mephistoblog.com

Rick O. wrote:

<% %> is used for erb. However, since config files use ruby, you’ll
have to use #{} for variables.

The reason Ryan’s sample has that is because he’s taking code from the
rails app generator. Once generated with a command like ‘rails foo’,
your app will have this:

config.action_controller.session = {
:session_key => ‘foo_session’,
:secret => ‘someuniquehash’
}

That makes sense. Not knowing exactly how the entry was processed, I was
unsure if somehow this was being processed by erb. I’ll post something
back to Ryan to make sure this is clear.

Thanks

On 3/1/07, Russell N. [email protected] wrote:

with single quotes? I’m presuming this will get evaluated somewhere else?
I’m a bit fuzzy on this and would totally appreciate any clarification.

RSL

Only if you have an app name variable in scope. Again, that is for
the generator only. For your rails app you can do something like
this:

config.action_controller.session = {
:session_key => ‘_foo_session’,
:secret => ‘whatever’
}

If you’re cryptographically challenged, you can use script/console to
generate something for you:

CGI::Session.generate_unique_id(‘something’)

Naturally, any string will do.


Rick O.
http://weblog.techno-weenie.net
http://mephistoblog.com

Heh. I put this in my new project too. I thought it looked strange
having
erb in the environment.rb file but when I used “#{}” [note the double
quotes] I ran into a heap of trouble. So, if I now understand correctly,
we
should just having something like

config.action_controller.session = {
:session_key => ‘_#{app_name}_session’,
:secret => ‘CGI::Session.generate_unique_id(#{app_name})’
}

with single quotes? I’m presuming this will get evaluated somewhere
else?
I’m a bit fuzzy on this and would totally appreciate any clarification.

RSL

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs