Skip to content

Instantly share code, notes, and snippets.

@JFickel
Created September 2, 2012 01:08
Show Gist options
  • Save JFickel/3593057 to your computer and use it in GitHub Desktop.
Save JFickel/3593057 to your computer and use it in GitHub Desktop.
app controller
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :current_user
require 'open-uri'
require 'json'
require 'nokogiri'
require 'ostruct'
def logged_in?
session[:user_id].present?
end
def current_user
@current_user ||= User.find_by_id(session[:user_id])
end
def redirect_if_not_team_admin(team, current_user)
team_admin_check = TeamRole.where('team_id = ? AND user_id = ? AND admin = ?', team.id, current_user.id, true)
if current_user.nil? || team_admin_check.nil?
flash[:error] = "Not authorized"
redirect_to root_url
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment