Skip to content

Instantly share code, notes, and snippets.

@kbouw
Created April 11, 2016 02:09
Show Gist options
  • Save kbouw/4daa6fe28f4e903fcf9fc8e39a2dae46 to your computer and use it in GitHub Desktop.
Save kbouw/4daa6fe28f4e903fcf9fc8e39a2dae46 to your computer and use it in GitHub Desktop.
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
before_filter :get_fbo
def after_sign_in_path_for(resource)
if current_user && current_user.admin
fbos_path
elsif current_user && !current_user.admin && !current_user.truck_id
orders_path
else
truck_index_path
end
end
private
def get_fbo
if current_user && !current_user.admin
current_user_domain = current_user.fbo.domain_name
if current_user_domain == request.subdomain
fbos = Fbo.where(domain_name: request.subdomain)
if fbos.count > 0
@fbo = fbos.first
elsif request.subdomain != 'www'
redirect_to root_url(subdomain: 'www')
end
else
redirect_to subdomain: current_user_domain
end
elsif request.subdomain != 'www'
redirect_to root_url(subdomain: 'www')
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment