Rails 3.2引擎如何在数据库中保存会话?

时间:2012-05-12 05:57:27

标签: ruby-on-rails ruby-on-rails-3 rails-engines session-storage

我有一个rails引擎代码。但是Rails :: Engine没有config.session_store变量。

module Admin
  class Engine < ::Rails::Engine
    isolate_namespace Admin

    config.autoload_paths << File.expand_path("../..", __FILE__)
    config.session_store :active_record_store

    config.generators do |g|
      g.javascript_engine :coffee
      g.stylesheet_engine :less
      g.template_engine :haml
      g.test_framework :rspec, :view_specs => false
    end
  end
end

我如何使用数据库会话存储?

1 个答案:

答案 0 :(得分:3)

解决方案:

module Admin
 class Engine < ::Rails::Engine
   isolate_namespace Admin

    config.autoload_paths << File.expand_path("../..", __FILE__)
    config.generators do |g|
      g.javascript_engine :coffee
      g.stylesheet_engine :less
      g.template_engine :haml
      g.test_framework :rspec, :view_specs => false
    end

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