Forum: Ruby on Rails session not persisting

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Will M. (Guest)
on 2006-05-29 09:32
I set up session to save to the db and everytime I hit a page I get a
new session entry created.  Some of them have session_ids of more than 5
digits, but lots of them have session_ids like 0.

Something is amiss.
Will M. (Guest)
on 2006-05-29 19:08
I built a test application and get the same behavior.  I cannot find any
documentation of this bug so I assume I've done something wrong.

I did follow the instructions in 'Agile Web D. with Rails' step
by step though.
Adam D. (Guest)
on 2006-05-29 19:14
(Received via mailing list)
can you paste the lines from environment.rb that you changed to put
sessions
in the DB ?

How did you create your session table in the DB ?

adam
Will M. (Guest)
on 2006-05-29 19:37
  # Use the database for sessions instead of the file system
  # (create the session table with 'rake db:sessions:create')
  config.action_controller.session_store = :active_record_store


class AddSessions < ActiveRecord::Migration
  def self.up
    create_table :sessions do |t|
      t.column :session_id, :string
      t.column :data, :text
      t.column :updated_at, :datetime
    end

    add_index :sessions, :session_id
  end

  def self.down
    drop_table :sessions
  end
end
Will M. (Guest)
on 2006-05-29 20:02
Here is the code in my controller that gets called often to store a
Score object to the session:

  private

  # Return the Score from this session, or create a new Score
  def find_score
    session[:score] ||= Score.new
  end

Here is my Score object:

class Score

  include Reloadable

  attr_reader :point_ids, :logged_test_id

  def initialize
    @point_ids = []
    @logged_test_id
  end

  def set_logged_test_id(logged_test_id)
    @logged_test_id = logged_test_id
  end

  def add_point_id(point_id)
    @point_ids << point_id
  end

end
This topic is locked and can not be replied to.