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