I just installed Rails 2.0.2.
While moving an application made in Rails 1.2 to Rails 2.0.2, I got a
problem of session.
I was using the variable @session[].
How should I change the old fashioned way to the new way, which is
cookie based session? How can I implement session or cookies in Rails 2?
I don’t want to keep using ActiveRecord based session.
Please give me a concrete help.
Links are also welcome.
Cookie based session is the default.
as to ‘@session’ it is deprecated, use just ‘session’ instead.
if you are upgrading an existing app to latest rails you will need to
update all the config/* files.
since you probably have made some changes to it, I think the best way
is to just create an
empty rails application and then compare the files in it’s ‘config’
dir with your app.
For example the section that deals with the session looks like that
(config/environment.rb):
Your secret key for verifying cookie session data integrity.
If you change this key, all old sessions will become invalid!
Make sure the secret is at least 30 characters and all random,
no regular words or you’ll be exposed to dictionary attacks.
config.action_controller.session = {
:session_key => ‘_qwe_session’,
:secret =>
‘3e59eabb481dc16c654402f79db3898004a1f83c5bc556349eb0dcf8385b667f33b0e4434fe950dcd0c4418f25bae29f014b535e990cb7c970ba563fb6a07988’
}
Use the database for sessions instead of the cookie-based default,
which shouldn’t be used to store highly confidential information
(create the session table with ‘rake db:sessions:create’)
config.action_controller.session_store = :active_record_store
As you can see ‘config.action_controller.session_store
= :active_record_store’ is commented out, so the default ‘cookie’
store is used.
Also note that rails now has a new directory config/initializers.
every .rb file that you put there will be executed during
initialization, so it is
better to add files there then adding stuff to config/environment.rb
itself.
On Apr 11, 9:17 am, Yohan Jo [email protected]
Thanks.
It works really fine.