Sharing session between your rails 4.x app and discourse

Discourse is rails application specifically built as a forum application which has gained a lot of momentum recently. Usually you want to integrate discourse with your main rails app, namely on a subdomain of its own, so one of the hottest topics is sharing session between the two apps.

Sharing session between rails 4 apps is rather simple, basically you have to set the same session cookie name and domain scope in session_store.rb:

    
        YourApp::Application.config.session_store :cookie_store, key: '_your_app', domain: '.yourdomain.com'
    

and you have to set the session secret to the same value in secret_token.rb, for example:

    
        YourApp::Application.config.secret_key_base = 'some_very_long_random_string'
    

The caveat with discourse is that secret_token.rb file by default uses Discourse::Application.config.secret_token = so make sure you replace the .secret_token = part with .secret_key_base =, failing that it will not work properly šŸ˜‰

Leave a Reply

Please Login to comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.