module ChangeNetwork
  extend ActiveSupport::Concern

  included do
    def change_user_network
      network = current_user.location_networks.find_by_id(params[:id])
      unless network.present?
        network = current_user.location_networks.first
        flash[:notice] = "Your network has been changed to #{network.network_name}"
      end
      current_user.current_network = network.id
      @current_network = current_user.current_network
      logger.info("Current Network in show <<<<<<#{@current_network.id}") unless @current_network.blank?
      if request.referer.present? 
        redirect_to request.referer
      else
        if @current_network.present?
         redirect_to home_path(@current_network)
        else
         redirect_to root_path
        end
      end
    end
  end
end