Skip to content

Instantly share code, notes, and snippets.

@novohispano
Last active August 29, 2015 14:11
Show Gist options
  • Save novohispano/7845caf9b7a01aa2de76 to your computer and use it in GitHub Desktop.
Save novohispano/7845caf9b7a01aa2de76 to your computer and use it in GitHub Desktop.
Multitenant Blogger Advanced.
# Original Router
Rails.application.routes.draw do
resources :articles
resources :comments
resource :account, only: [:show] do
get :work
end
get '/login' => 'sessions#new'
post '/login' => 'sessions#create'
get '/logout' => 'sessions#destroy'
get '/dashboard' => 'dashboard#show'
root to: 'articles#index'
end
# Multitenant Router
Rails.application.routes.draw do
resources :tenants, path: "", param: :slug, except: [:index]
namespace :tenants, as: :tenant, path: "/:slug" do
get '/login' => 'sessions#new'
post '/login' => 'sessions#create'
get '/logout' => 'sessions#destroy'
get '/dashboard' => 'dashboard#show'
resources :articles
resources :comments
resource :account, only: [:show] do
get :work
end
end
root to: 'tenants#index'
end
class Tenant < ActiveRecord::Base
has_many :authors
has_many :articles, through: :authors
validates :name, uniqueness: true
validates :slug, uniqueness: true
before_save :generate_slug
def generate_slug
self.slug = name.parameterize
end
end
# Original Controller
class ArticlesController < ApplicationController
end
# New Controller
class Tenants::ArticlesController < ApplicationController
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment