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
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
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
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
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
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
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
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
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
To set current user
# File app/controllers/application_controller.rb, line 68 def set_current_user User.current = current_user end
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
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
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