Adding cookie session store back to Rails API app

后端 未结 4 684
天命终不由人
天命终不由人 2020-11-29 02:13

I have a Rails-API app. More or less \"out of the box\" but I want to add back cookie-based session store. Here is what I\'ve done:

app/controllers/application_contr

4条回答
  •  迷失自我
    2020-11-29 02:52

    If you're on Rails 5, and want to preserve config.api_only = true you could extend the middleware to add the sessions layer, adding this code after class Application < Rails::Application in config/application.rb

    config.middleware.use ActionDispatch::Cookies
    config.middleware.use ActionDispatch::Session::CookieStore, key: '_namespace_key'
    

    This could come in handy when you want to have a rails api-only enabled app but have to manage user sessions with an administration panel like ActiveAdmin or Rails_Admin.

提交回复
热议问题