Last active
August 29, 2015 14:11
-
-
Save novohispano/7845caf9b7a01aa2de76 to your computer and use it in GitHub Desktop.
Multitenant Blogger Advanced.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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