simonlehmann
simonlehmann

Reputation: 882

Storing value in session vs in DB - Rails

I am building a team management app in Rails where :users has many :organizations. I would like for users to be able to switch between organisations and manage them individually without having the /organizations/:id/ in the URL. Due to Wildcard SSL certificate costs, I would also like to avoid using subdomains to identify the organization.

As I understand it, this leaves two options:

  1. Store the current organization in the DB.
  2. Store the current organization in the session.

What would be the best option here?

Thanks

Upvotes: 0

Views: 47

Answers (1)

Michael Chaney
Michael Chaney

Reputation: 3031

Simply store it in the session, there's no reason to do it any other way. I would also create a before_action in the application controller to automatically load the organization into an instance variable available to your controllers and views.

Upvotes: 2

Related Questions