Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

uninitialized constant ActiveRecord::SessionStore with gem 'activerecord-session_store'

We are upgrading Rails 3.2 engine to Rails 4.2.0 on ruby 2.0.0. Gem 'activerecord-session_store' was added to engine's gemspec following gem's instruction:

 s.add_dependency 'activerecord-session_store' 

and added following in initializers/session_store.rb under dummy:

Dummy::Application.config.session_store :active_record_store, :key => '_my_app_session'

then, we did bundle install. When we ran:

bundle exec rails generate active_record:session_migration

There is the error from the gem's generator:

/activerecord-session_store-0.1.1/lib/generators/active_record/session_migration_generator.rb:16:in `session_table_name': uninitialized co
nstant ActiveRecord::SessionStore (NameError).

We move the gem into engine's Gemfile and same error. Why the SessionStore is still not initialized?

Update

In engine's engine.rb under lib, the session table is pointed to:

initializer "Authentify.add_middleware" do |app|
  ActiveRecord::SessionStore::Session.table_name = 'authentify_sessions'
  app.middleware.use ActiveRecord::SessionStore
end 

The setup works for Rails 3.2.

like image 711
user938363 Avatar asked Oct 12 '25 14:10

user938363


2 Answers

If you were not using the default table name for sessions, set:

ActiveRecord::SessionStore::Session.table_name = 'your_old_session_table'

in config/application.rb.

Additional configuration.

like image 142
holographic-principle Avatar answered Oct 14 '25 15:10

holographic-principle


What we did is to add gem 'activerecord-session_store' to engine's Gemfile in addition to the .gemspec. The error disappeared.

like image 25
user938363 Avatar answered Oct 14 '25 14:10

user938363



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!