Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Aplicações Multitenant com Rails

leonogueira
September 19, 2015

Aplicações Multitenant com Rails

Apresentação para a RubyConf Brasil 2015 - Aplicações Multitenant em Rails

leonogueira

September 19, 2015
Tweet

More Decks by leonogueira

Other Decks in Programming

Transcript

  1. 12

  2. 13

  3. “Over 150,000 online shops such as Tesla and GitHub During

    the weekend of Black Friday and Cyber Monday over a million requests per minute resulting in over 6,000 orders per minute (~50 million dollars.)” 14
  4. 16

  5. 18

  6. 24

  7. # app/controllers/application_controller.rb class ApplicationController < ActionController::Base include SetTenant before_filter :set_tenant

    # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception end 30
  8. Um modelo para controle dos usuários rails g model User

    name:string password_digest:string active:boolean admin:boolean 36
  9. #app/controllers/concerns/authentication.rb module Authentication extend ActiveSupport::Concern included do helper_method :current_user, :logged_in?

    end private def current_user @current_user ||= User.find_by_id(session[:user_id]) if session[:user_id] end def logged_in? current_user.present? end def redirect_logged_user redirect_to root_path if logged_in? end def require_admin_user end def require_management_user end def require_logged_user unless logged_in? end end def return_url ... end end 37
  10. Um modelo para controle dos Tenants rails g model Account

    subdomain:string name:string ... 38
  11. 50

  12. 51

  13. 53