application_controller.rb revision 2bc45485d0fe7200960bd17f1b81ea477bf16bef
1516N/Aclass ApplicationController < ActionController::Base
50N/A
50N/A protect_from_forgery
50N/A ensure_security_headers
50N/A
50N/A include Pagination
50N/A include PathHelpers
50N/A include ApplicationHelper
50N/A
50N/A # CanCan Authorization
50N/A rescue_from CanCan::AccessDenied do |exception|
50N/A if request.format.html?
50N/A redirect_to root_url, alert: exception.message
50N/A else
50N/A render \
50N/A status: :forbidden,
50N/A content_type: 'text/plain',
50N/A text: exception.message
50N/A end
50N/A end
50N/A
50N/A if defined? PG
2026N/A # A foreign key constraint exception from the database
2026N/A rescue_from PG::Error do |exception|
2026N/A message = exception.message
50N/A if message.include?('foreign key constraint')
60N/A logger.warn(message)
202N/A # shorten the message
50N/A message = message.match(/DETAIL: .+/).to_s
50N/A
1431N/A redirect_to :back,
1431N/A flash: {error: "Whatever you tried to do - the server is unable to process your request because of a foreign key constraint. (#{message})" }
1431N/A else
1755N/A # anything else
1352N/A raise exception
1618N/A end
72N/A end
1431N/A end
50N/A
1618N/A
50N/A protected
50N/A
50N/A def authenticate_admin!
66N/A unless admin?
135N/A flash[:error] = 'you need admin privileges for this action'
66N/A redirect_to :root
66N/A end
50N/A end
1846N/A
1846N/A def after_sign_in_path_for(resource)
1846N/A root_path
1846N/A end
1846N/A
580N/A def after_sign_out_path_for(resource)
50N/A request.referrer
2054N/A end
50N/A
1846N/A def display_all?
2054N/A params[:all].present?
1846N/A end
1846N/A
1846N/A def paginate_for(collection)
50N/A Kaminari.paginate_array(collection).page(params[:page])
1846N/A end
235N/A
1618N/A def locid_for(resource, *commands, **query_components)
1846N/A iri = "#{request.base_url}#{resource.locid}"
1846N/A iri << "///#{commands.join('///')}" if commands.any?
1846N/A iri << "?#{query_components.to_query}" if query_components.any?
1846N/A iri
580N/A end
63N/A
72N/A helper_method :display_all?
72N/A helper_method :locid_for
202N/A
72N/Aend
72N/A