2

我有一个 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

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

4

1 回答 1

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
于 2012-05-14T04:24:25.043 回答