application_controller.rb revision 5a57115bbe7d39803b4f2b1f5dbf6f0f760d9169
1516N/Aclass ApplicationController < ActionController::Base
39N/A protect_from_forgery
39N/A
39N/A include Pagination
39N/A
39N/A # CanCan Authorization
39N/A rescue_from CanCan::AccessDenied do |exception|
39N/A redirect_to root_url, :alert => exception.message
39N/A end
39N/A
39N/A if defined? PG
39N/A # A foreign key constraint exception from the database
39N/A rescue_from PG::Error do |exception|
39N/A message = exception.message
39N/A if message.include?('foreign key constraint')
39N/A logger.warn(message)
39N/A # shorten the message
39N/A message = message.match(/DETAIL: .+/).to_s
39N/A
39N/A redirect_to :back,
39N/A :flash => {:error => "Whatever you tried to do - the server is unable to process your request because of a foreign key constraint. (#{message})" }
926N/A else
926N/A # anything else
1890N/A raise exception
926N/A end
39N/A end
1713N/A end
2026N/A
342N/A protected
1516N/A
1636N/A helper_method :admin?
1386N/A def admin?
838N/A current_user.try(:admin?)
39N/A end
51N/A
1352N/A def authenticate_admin!
1066N/A unless admin?
1231N/A flash[:error] = "you need admin privileges for this action"
1352N/A redirect_to :root
1890N/A end
296N/A end
39N/A
1713N/Aend
1713N/A