class ApplicationController

Public Instance Methods

check_for_previous_confirmed_sessions() click to toggle source

If there is confirmed session but not paid than forcefully redirect user to dashboard page

# File app/controllers/application_controller.rb, line 61
def check_for_previous_confirmed_sessions
  if logged_in? && current_user.previous_confirmed_sessions.exists?
    request.xhr? ? (redirect_via_turbolinks_to dashboard_path) : (redirect_to dashboard_path)
  end
end
find_university_by_subdomain() click to toggle source

To find university by their subdomain

# File app/controllers/application_controller.rb, line 33
def find_university_by_subdomain
  if subdomain_present?
    ActsAsTenant.current_tenant = University.find_by!(subdomain: request.subdomains.last)
    unless ActsAsTenant.current_tenant
      redirect_to root_url(subdomain: false)
    end
  else
    ActsAsTenant.current_tenant = nil
  end
end
find_current_video_sessions() click to toggle source

To find ongoing video sessions

# File app/controllers/application_controller.rb, line 19
def find_current_video_sessions
  if logged_in? and !current_user.super_admin?
    @video_sessions = current_user.related_sessions.video_sessions.ongoing_sessions.includes(:video_session_room)
  end
end
init_chat_for(group) click to toggle source

To initialize group chat

# File app/controllers/application_controller.rb, line 45
def init_chat_for(group)
  @conversation = group.chat_conversation || group.create_chat_conversation(grouped: true)
  @conversation.init_chat_for(current_user)
  current_user.chat_activities.find_or_create_by(chat_conversation: @conversation)
end
init_chat_with(user_ids = [], conversation_id=nil) click to toggle source

To initialize chat with specific user

# File app/controllers/application_controller.rb, line 52
def init_chat_with(user_ids = [], conversation_id=nil)
  @conversation = ChatConversation.find_or_create_conversation_for(current_user, user_ids, conversation_id)
  if @conversation
    @conversation.init_chat_for(current_user)
    current_user.chat_activities.find_or_create_by(chat_conversation: @conversation)
  end
end
next_profile_question(current_question = 0) click to toggle source

To get next profile question

# File app/controllers/application_controller.rb, line 105
def next_profile_question(current_question = 0)
  return 'complete' if cookies[:profile_question]
  current_question = 0 if current_question >= User::PROFILE_QUESTION.size
  User::PROFILE_QUESTION[current_question..-1].each do |attribute|
    attr1, attr2 = attribute.split(':', 2)
    if attr2
      return "#{attr1}/#{attr2}" if current_user.send(attr1).blank?
      if attr1 == "profile_image"
       return "#{attr1}/#{attr2}" if current_user.send(attr1).send(attr2).blank?
      else
        return "#{attr1}/#{attr2}" if current_user.send(attr1).first.send(attr2).blank?
      end
    else
      unless current_user.student? && attr1 == 'rate'
        return attr1 if current_user.send(attr1).blank?
      end
    end
  end
  return 'complete'
end
not_authenticated() click to toggle source

Redirect and show alert when the user is not authenticated

# File app/controllers/application_controller.rb, line 88
def not_authenticated
  redirect_to root_url, :alert => "First login to access this page."
end
redirect_to_admin_dashboard() click to toggle source

To redirect page on to admin dashboard

# File app/controllers/application_controller.rb, line 26
def redirect_to_admin_dashboard
  if subdomain_present? and current_user and current_user.super_admin?
    redirect_to admin_path(subdomain: false)
  end
end
require_subdomain() click to toggle source

Raise exception if subdomain not found

# File app/controllers/application_controller.rb, line 93
def require_subdomain
  if request.subdomain.blank? or request.subdomain.match(/\Awww\z/)
    raise DatabaseNotFound, "Cannot find tenant #{environmentify(tenant)}"
  end
end
set_current_user() click to toggle source

To set current user

# File app/controllers/application_controller.rb, line 68
def set_current_user
  User.current = current_user
end
set_default_metatags() click to toggle source

To set default metatages

# File app/controllers/application_controller.rb, line 73
def set_default_metatags
  tags = {
    'time-zone' => Time.zone.name,
    'current-date' => Date.today_in_time_zone.to_s(:db)
  }
  if logged_in? and current_user.is_registration_completed? and ActsAsTenant.current_tenant and ActsAsTenant.current_tenant.pusher_configuration.try(:enabled)
    tags.merge!({
      'pusher-api-key' => ActsAsTenant.current_tenant.pusher_configuration.try(:api_key),
      'current-user-id' => current_user.try(:id)
    })
  end
  gon.meta_tags = set_meta_tags(tags)
end
subdomain_present?() click to toggle source

To check if subdomain is present

# File app/controllers/application_controller.rb, line 100
def subdomain_present?
  request.subdomain.present? and !request.subdomain.match(/\Awww\z/)
end

Protected Instance Methods

check_registration() click to toggle source

If current user not completed with registration than go to the next profile step

# File app/controllers/application_controller.rb, line 129
def check_registration
  if current_user and !current_user.is_registration_completed?
    redirect_to edit_profile_path(current_user.next_profile_step)
  end
end
render_404() click to toggle source

show error 404 “not found”

# File app/controllers/application_controller.rb, line 136
def render_404
  respond_to do |format|
    format.html { render :file => "#{Rails.root}/public/404", :layout => false, :status => :not_found }
    format.xml  { head :not_found }
    format.any  { head :not_found }
  end
end