James Byrne wrote in post #975693:
> I have asked about this problem elsewhere and have as yet not had any
> answer.
>
> I cannot determine what is wrong with our Session store
> configuration.  In Rails2 we used AR store with AuthLogic without
> problem.  When we switched to Rails3 we ended up using cookie store
> because we could not get AR store to work.  Now I would like to
> discover why we are having this problem and fix it.
>
> What is NOT happening is that the session_id in the sessions model
> is not being initialized.  Therefore we see this DBMS error:
>
>       PGError: ERROR:  null value in column "session_id" violates
> not-null constraint
>       : INSERT INTO "sessions" ("session_id", "updated_at",
> "created_at", "lock_version", "data") VALUES (NULL, .  .  .
>
> We never explicitly set session_id in Rails2 and I cannot figure out
> how to do so so now.  Does anyone know hat one must do to initialize
> session_id from inside AuthLogic?

AFAIK the choice of session store should be independent of any 
authentication framework. Have you tried creating new blank Rails 3.0 
application and checking the session store configuration?

Here is what I see from doing so:

./initializers/session_store.rb
-----------------------------
# Be sure to restart your server when you modify this file.

# Demo::Application.config.session_store :cookie_store, :key => 
'_demo_session'

# 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 "rails generate session_migration")
Demo::Application.config.session_store :active_record_store
-----------------------------

I simple commented out the cookie store config and replaced it with the 
AR session store config. then ran the generator as shown above.

./db/schema.rb
-----------------------------
  create_table "sessions", :force => true do |t|
    t.string   "session_id", :null => false
    t.text     "data"
    t.datetime "created_at"
    t.datetime "updated_at"
  end

  add_index "sessions", ["session_id"], :name => 
"index_sessions_on_session_id"
  add_index "sessions", ["updated_at"], :name => 
"index_sessions_on_updated_at"
-----------------------------

./app/controllers/welome_controller.rb
-----------------------------
class ApplicationController < ActionController::Base
  protect_from_forgery

  before_filter :force_session_use

private
  def force_session_use
    session[:user_id] = 1
  end
end
-----------------------------

A little code to force a value into the session.

./app/views/welcome/index.html.erb
-----------------------------
<h1>Welcome#index</h1>
<p>Session contains user_id: <%= session[:user_id] %></p>
-----------------------------

Read the value back from the session.

sessions table in database
-----------------------------
sqlite> select * from sessions;
id|session_id|data|created_at|updated_at
1|4e3b2648c9a9fb292fc45b756f7e8908|BAh7B0kiDHVzZXJfaWQGOgZFRmkGSSIQX2NzcmZfdG9rZW4GOwBGSSIxeTdI
VEdlRDJ1ZURQa0kwdEZOcjNaSi9wVE1NUVg5Y2ZyMDdQSTJXMWdWdz0GOwBG
|2011-01-18 20:07:12.597419|2011-01-18 20:07:12.597419
-----------------------------

And finally we get the session data stored in the database.

No AuthLogic or anything else involved. I'd check your session store 
configuration against what I showed here. Good luck.

-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to