Skip to content

Commit

Permalink
try again
Browse files Browse the repository at this point in the history
  • Loading branch information
patwalls committed Nov 4, 2018
1 parent a0cf361 commit 091da1b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
24 changes: 12 additions & 12 deletions app/controllers/i/posts_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
class I::PostsController < ApplicationController
def index
logger.debug "---------"
logger.debug "---------"
logger.debug request.host
logger.debug "---------"
logger.debug "---------"
redirect_to google_drive_authorize_path if current_user && current_user.google_auth_token.nil?
@user = User.find_by(username: subdomain_or_param)
@user = User.find_by(username: host_or_param)
return redirect_to root_path unless @user

if params[:drafts]
Expand All @@ -12,7 +17,7 @@ def index
end

def show
@user = User.find_by(username: subdomain_or_param)
@user = User.find_by(username: host_or_param)
return redirect_to root_path unless @user

@post = @user.posts.friendly.find(params[:post_id])
Expand All @@ -27,16 +32,11 @@ def show
private

def subdomain_or_param
logger.debug "-----------------"
logger.debug "-----------------"
logger.debug "-----------------"
logger.debug "-----------------"
logger.debug request.host
logger.debug "-----------------"
logger.debug "-----------------"
logger.debug "-----------------"
logger.debug "-----------------"
(request.subdomain.present? && request.subdomain != "www") ? User::DOMAIN_MAPPING[request.subdomain] : params[:username]
(request.subdomain.present? && request.subdomain != "www") ? request.subdomain : params[:username]
end

def host_or_param
(request.host.present? && request.host != "localhost" && request.host != "youdontneedwp.com" && request.host != "www.youdontneedwp.com") ? User::DOMAIN_MAPPING[request.host] : params[:username]
end

def parse_links(doc)
Expand Down
7 changes: 6 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
Rails.application.routes.draw do
devise_for :users

constraints(subdomain: 'patwalls.co') do
constraints(subdomain: 'patwalls') do
root "i/posts#index", as: 'subdomain_blog_index'
get '/:post_id', to: 'i/posts#show', as: 'subdomain_blog_show'
end

constraints(host: 'patwalls.co') do
root "i/posts#index", as: 'host_blog_index'
get '/:post_id', to: 'i/posts#show', as: 'host_blog_show'
end

root 'welcome#index'

resource :profile, only: [:show], controller: 'profile'
Expand Down

0 comments on commit 091da1b

Please sign in to comment.