Rails 2.3.2 and config.action_controller.session

Further on migrating my ancient 1.8.6 Rails 2.3.2 app from Windows to Linux Mint, whatever I do, I keep getting the same error pertaining to " ** A key is required to write a cookie containing the session data. Use
config.action_controller.session = { :key => “_myapp_session”, :secret => “some secret phrase” } in config/environment.rb."** This is true if I run run ruby script/server, or rake rails:update. However, in my config/environent.rb, I already have this statement the error is telling me I needed (in fact, it was commented out, but uncommenting it changes nothing for me, I keep getting the same error whenever I go to run something here). Anyone have an idea where else I can look here? Thaks, RVic
ruby script/server
/home/user/.rvm/gems/ruby-1.8.6-p420/gems/actionpack-2.3.2/lib/action_controller/session/cookie_store.rb:163:in ensure_session_key': A key is required to write a cookie containing the session data. Use config.action_controller.session = { :key => "_myapp_session", :secret => "some secret phrase" } in config/environment.rb (ArgumentError) from /home/user/.rvm/gems/ruby-1.8.6-p420/gems/actionpack-2.3.2/lib/action_controller/session/cookie_store.rb:74:in initialize’
from /home/user/.rvm/gems/ruby-1.8.6-p420/gems/actionpack-2.3.2/lib/action_controller/middleware_stack.rb:72:in new' from /home/user/.rvm/gems/ruby-1.8.6-p420/gems/actionpack-2.3.2/lib/action_controller/middleware_stack.rb:72:in build’
from /home/user/.rvm/gems/ruby-1.8.6-p420/gems/actionpack-2.3.2/lib/action_controller/middleware_stack.rb:116:in build' from /home/user/.rvm/gems/ruby-1.8.6-p420/gems/activesupport-2.3.2/lib/active_support/inflector.rb:361:in inject’
from /home/user/.rvm/gems/ruby-1.8.6-p420/gems/actionpack-2.3.2/lib/action_controller/middleware_stack.rb:116:in each' from /home/user/.rvm/gems/ruby-1.8.6-p420/gems/actionpack-2.3.2/lib/action_controller/middleware_stack.rb:116:in inject’
from /home/user/.rvm/gems/ruby-1.8.6-p420/gems/actionpack-2.3.2/lib/action_controller/middleware_stack.rb:116:in build' ... 8 levels... from ./script/../config/boot.rb:11:in boot!’
from ./script/…/config/boot.rb:110
from script/server:2:in `require’
from script/server:2

Are you sure your time wouldn't be better spent just moving straight
to current versions of Ruby and Rails? :slight_smile:

It might actually be easier than what you're doing now, and at the end
you'd have something besides a running but obsolete application with
known security vulnerabilities...

Just a suggestion!

Hassan,

Oh I certainly will be migrating it -- I;ve just got the order though to
get this thing up and running in a linux vm asap. Hopefully, Im not far
from that. But there;s a lot that Iwill have to migrate to the new
mechanisms (routes are different, invoking the server is different, etc.)
Thank you!

Can you paste your environment.rb here please?

Colin

Thanks Colin!

# Be sure to restart your web server when you modify this file.

# Uncomment below to force Rails into production mode when
# you don't control web/app server and can't set it the proper way
# ENV['RAILS_ENV'] ||= 'production'

# Specifies gem version of Rails to use when vendor/rails is not present
# RAILS_GEM_VERSION = '2.1.2' unless defined? RAILS_GEM_VERSION

# Bootstrap the Rails environment, frameworks, and default configuration
require File.join(File.dirname(__FILE__), 'boot')
require 'paginator'

Rails::Initializer.run do |config|

  # Settings in config/environments/* take precedence those specified here

  # Skip frameworks you're not going to use
  #config.frameworks -= [ :action_web_service, :action_mailer ]

  # Add additional load paths for your own custom dirs
  # config.load_paths += %W( #{RAILS_ROOT}/extras )
  config.load_paths += %W( #{RAILS_ROOT}/app/reports )

  # Required for Ruports: ############
   config.after_initialize do
      require "ruport"
    end
  # **SEE CONFIG_LOAD_PATHS ABOVE and require "app/reports/templates"
BELOW**

Can you paste your environment.rb here please?

Colin

Thanks Colin!

# Be sure to restart your web server when you modify this file.

# Uncomment below to force Rails into production mode when
# you don't control web/app server and can't set it the proper way
# ENV['RAILS_ENV'] ||= 'production'

# Specifies gem version of Rails to use when vendor/rails is not present
# RAILS_GEM_VERSION = '2.1.2' unless defined? RAILS_GEM_VERSION

The above line should not be commented out, but should of course
reference '2.3.2'. I don't know whether that might have anything to
do with it or not.

# Bootstrap the Rails environment, frameworks, and default configuration
require File.join(File.dirname(__FILE__), 'boot')
require 'paginator'

The line above should not be there, again I don't know whether it is
relevant to the problem.

Rails::Initializer.run do |config|

  # Settings in config/environments/* take precedence those specified here

  # Skip frameworks you're not going to use
  #config.frameworks -= [ :action_web_service, :action_mailer ]

  # Add additional load paths for your own custom dirs
  # config.load_paths += %W( #{RAILS_ROOT}/extras )
  config.load_paths += %W( #{RAILS_ROOT}/app/reports )

  # Required for Ruports: ############
   config.after_initialize do
      require "ruport"
    end
  # **SEE CONFIG_LOAD_PATHS ABOVE and require "app/reports/templates"
BELOW**
  ###########################

  # Force all environments to use the same logger level
  # (by default production uses :info, the others :debug)
  # config.log_level = :debug

  # Use the database for sessions instead of the file system
  # which shouldn't be used to store highly confidential information
  # (create the session table with 'rake db:sessions:create')

Have you done the above? Either do that and/or comment out the line
below, at least until it is working.

  config.action_controller.session_store = :active_record_store

  # Use SQL instead of Active Record's schema dumper when creating the test
database.
  # This is necessary if your schema can't be completely dumped by the
schema dumper,
  # like if you have constraints or database-specific column types
  # config.active_record.schema_format = :sql

  # Activate observers that should always be running
  # config.active_record.observers = :cacher, :garbage_collector

  # Make Time.zone default to the specified zone, and make Active Record
store time values
     # in the database in UTC, and return them converted to the specified
local zone.
     # Run "rake -D time" for a list of tasks for finding time zone names.
Comment line to use default local time.
  config.active_record.default_timezone = :utc

  # See Rails::Configuration for more options

  # 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 = {
    :key => "_gg_session",

That should be :session_key I think, at least that is what I have, in
which case the error message is wrong.

   :secret =>
"caf079519f0a811fa0ba9a0a3202c93f62d9f86ca4f1981harverdouccioe55e3869ee4aa8cbb48aecb518f1059103b7eb49b513f4d6ddc40d92e9488785eb90689229ad"
  }

  config.gem "authlogic"
  config.gem "actionmailer"
  config.gem "calendar_date_select"
  config.gem "paginator"
  config.gem "builder"
end

require "app/reports/templates"

# Add new inflection rules using the following format
# (all these examples are active by default):
# Inflector.inflections do |inflect|
# inflect.plural /^(ox)$/i, '\1en'
# inflect.singular /^(ox)en/i, '\1'
# inflect.irregular 'person', 'people'
# inflect.uncountable %w( fish sheep )
# end

# Include your application configuration below

Colin

Colin, I made the changes you said to make here (I did, well before, do
rake db:sessions:create and have the table resident in the db). I;ve lso
tried using :session_key in instead of :key.....noe of which seems to be
affecting it:

ruby script/server
/home/user/.rvm/gems/ruby-1.8.6-p420/gems/actionpack-2.3.2/lib/action_controller/session/cookie_store.rb:163:in
`ensure_session_key': A key is required to write a cookie containing the
session data. Use config.action_controller.session = { :key =>
"_myapp_session", :secret => "some secret phrase" } in
config/environment.rb (ArgumentError)
    from
/home/user/.rvm/gems/ruby-1.8.6-p420/gems/actionpack-2.3.2/lib/action_controller/session/cookie_store.rb:74:in
`initialize'

I think the issue may be something else Colin. For example, this error seems to crop up no matte what the command is:

user@Mint15-32 ~/ggrip/ggripv2 $ rake rails:update
rake aborted!
A key is required to write a cookie containing the session data. Use config.action_controller.session = { :key => “_myapp_session”, :secret => “some secret phrase” } in config/environment.rb

/home/user/.rvm/gems/ruby-1.8.6-p420/gems/actionpack-2.3.2/lib/action_controller/session/cookie_store.rb:163:in `ensure_session_key’

It is very odd, firstly it should not be using the cookie store, and
if it were then you have provided the session key. I have tried it
and it works for me with either :key or :session_key, and if I enable
the active_record_store then it does not ask in the first place.

Can you post development.rb please.

Colin

That is not all that surprising, it has to load the environment in
order to run rake.

Colin

# Settings specified here will take precedence over those in
config/environment.rb
#require "ruby-debug"

# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for
development
# since you don't have to restart the webserver when you make code changes.
config.cache_classes = false

# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true

# Enable the breakpoint server that script/breakpointer connects to
#config.breakpoint_server = true

# Show full error reports and disable caching
config.action_controller.consider_all_requests_local = true
config.action_controller.perform_caching = false
#config.action_view.cache_template_extensions = false
config.action_view.debug_rjs = true

# config/environments/development.rb
config.action_mailer.raise_delivery_errors = true

# set delivery method to :smtp, :sendmail or :test
config.action_mailer.delivery_method = :smtp

#set default type to html. Options are "text/plain", "text/html", and
"text/enriched". The default value is "text/plain".
config.action_mailer.default_content_type = "text/html"

# these options are only needed if you choose smtp delivery
config.action_mailer.smtp_settings = {
  :address => 'outgoing.verizon.net',
  :port => 25,
  :domain => 'www.example.com',
  :authentication => :login,
  :user_name => 'cfgsr',
  :password => 'p6687sq5'
}

That all looks ok. Sorry I am out of ideas. I can only suggest that
you try making a new app (I can't remember how to do that in rails 2,
you will have to look it up if you don't know), and see if that works.
Then if that works add stuff in from your app till it breaks.

Colin

Wait,

Stupid me.

The database login parameters have changed – when I change that, it gets past that error (give me a new one, of coursem but that must be the problem). I fixed it in database.yml.

And…once I get that one fixed…I’m right back to the original error!

Thanks Colin.

How would you enable active_record_store? Perhaps I should try that first?

I think there’s more wrong here than what the error message suggests. For example:

user@Mint15-32 ~/ggrip/ggripv2 $ gem install rails -v 2.3.2
Successfully installed rails-2.3.2
1 gem installed

Installing ri documentation for rails-2.3.2…
Installing RDoc documentation for rails-2.3.2…

user@Mint15-32 ~/ggrip/ggripv2 $ rails -v
The program ‘rails’ can be found in the following packages:

  • rails
  • ruby-railties-3.2
    Try: sudo apt-get install

When I did rails - v, shouldn;t it have just returned 2.3.2 ?

I think there's more wrong here than what the error message suggests. For example:

user@Mint15-32 ~/ggrip/ggripv2 $ gem install rails -v 2.3.2
Successfully installed rails-2.3.2
1 gem installed
Installing ri documentation for rails-2.3.2...
Installing RDoc documentation for rails-2.3.2...

user@Mint15-32 ~/ggrip/ggripv2 $ rails -v
The program 'rails' can be found in the following packages:
* rails
* ruby-railties-3.2
Try: sudo apt-get install <selected package>

When I did rails - v, shouldn;t it have just returned 2.3.2 ?

Yes. I'm late to the party here, but are you using rvm on this server? What does your PATH look like? If you aren't using rvm, then have you tried using sudo, as in

sudo gem install rails -v 2.3.2

Without rvm, you may be installing these binaries somewhere that your PATH can't find them.

Walter

Walter,

I AM using rvm. My path:

user@Mint15-32 ~/ggrip/ggripv2 $ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/user/.rvm/bin

Uh, well. It looks like rvm is installed, but you're not actually using it.
If you were, your path would start with the rvm bin directories for the
ruby and gemset you'd selected. Which it obviously doesn't.

Easy test: what does `rvm current` report? If it's not what you want,
that's the first thing to fix.

user@Mint15-32 ~/ggrip/ggripv2 $ rvm current
ruby-1.8.6-p420

which is correct. The /home/user/.rvm/bin in the PATH is correct, yes? What
else are you saying should be in the PATH? THanks.