DEV Community

loading...

Discussion on: Simple Multitenancy in Rails

Collapse
ritikesh profile image
Ritikesh Author

Hey, Thanks for reading. You can easily include the concerns and use them as you go. For eg.)

If you have a user class that you want to make current'able, add the following code:

# app/models/user.rb

class User < ActiveRecord::Base
  include ActsAsCurrent
end

# app/helpers/application_helper.rb

class ApplicationHelper
  def current_user
    return User.current if User.current
    User.find(session[:id]).make_current
  end
end

# app/controllers/application_controller.rb

class ApplicationController < ActionController::Base

  after_filter :reset_current_user

  private
  def reset_current_user
    User.reset_current
  end
end