Search code examples
ruby-on-railsrubysessioncookiesrack

Specifying Rails session cookies in rack


I see this same documented code copy and pasted everywhere in regards to setting up cookies in rails:

use Rack::Session::Cookie, :key => 'rack.session',
                           :domain => 'foo.com',
                           :path => '/',
                           :expire_after => 2592000,
                           :secret => 'change_me'

All parameters are optional.

But nobody ever specifies WHERE in the rails app this should be implemented, everytime I put it in an initializer, it says 'use' is not a method.

Could someone please point me in the right direction with this?


Solution

  • When asking a question on Stack Overflow you should include sources to help others understand your question. For example, you say "I see this same documented code copy and pasted everywhere" but when I search github.com for use Rack::Session::Cookie there is only one result, and when I search on any site there are only 13 results.

    Those results all show that this is a feature used by apps that want to take advantage of Rack libraries, not Rails apps. If you're using Rails you don't need to do this configuration anywhere because Rails already has session support. (If you're certain that you do need it then please explain in greater detail why.)

    To understand why you don't need to do this in Rails please take a look at these excellent articles:

    The specific example I found of use Rack::Session::Cookie is for Sinatra, which like Rails is a framework and DSL for web apps. The method use is a part of Sinatra and examples of use can be found in the Sinatra documentation.