module Refinery::ApplicationController

Public Class Methods

included(base) click to toggle source
# File lib/refinery/application_controller.rb, line 6
def self.included(base) # Extend controller
  base.helper_method :home_page?,
                     :local_request?,
                     :from_dialog?,
                     :admin?,
                     :current_refinery_user,
                     :authorisation_manager, :authorization_manager

  base.protect_from_forgery with: :exception # See ActionController::RequestForgeryProtection

  base.send :include, Refinery::Crud # basic create, read, update and delete methods

  if Refinery::Core.rescue_not_found
    base.rescue_from ::ActiveRecord::RecordNotFound,
                     ::AbstractController::ActionNotFound,
                     ::ActionView::MissingTemplate,
                     :with => :error_404
  end
end

Public Instance Methods

admin?() click to toggle source
# File lib/refinery/application_controller.rb, line 26
def admin?
  %r{\Aadmin/} === controller_name
end
current_refinery_user() click to toggle source
# File lib/refinery/application_controller.rb, line 51
def current_refinery_user
  authorisation_manager.current_user
end
error_404(exception = nil) click to toggle source
# File lib/refinery/application_controller.rb, line 30
def error_404(exception = nil)
  # fallback to the default 404.html page.
  file = Rails.root.join 'public', '404.html'
  file = Refinery.roots('refinery/core').join('public', '404.html') unless file.exist?
  render :file => file.cleanpath.to_s.gsub(%r{#{file.extname}$}, ''),
         :layout  => false, :status => 404, :formats => [:html]
  return false
end
from_dialog?() click to toggle source
# File lib/refinery/application_controller.rb, line 39
def from_dialog?
  params[:dialog] == 'true' || params[:modal] == 'true'
end
home_page?() click to toggle source
# File lib/refinery/application_controller.rb, line 43
def home_page?
  %r{^#{Regexp.escape(request.path)}} === refinery.root_path
end
local_request?() click to toggle source
# File lib/refinery/application_controller.rb, line 47
def local_request?
  Rails.env.development? || /(::1)|(127.0.0.1)|((192.168).*)/ === request.remote_ip
end

Protected Instance Methods

authorisation_manager() click to toggle source
# File lib/refinery/application_controller.rb, line 70
def authorisation_manager
  @authorisation_manager ||= ::Refinery::Core::AuthorisationManager.new
end
Also aliased as: authorization_manager
authorization_manager()

We ❤ you, too ️

present(model) click to toggle source

use a different model for the meta information.

# File lib/refinery/application_controller.rb, line 58
def present(model)
  @meta = presenter_for(model).new(model)
end
presenter_for(model, default = BasePresenter) click to toggle source
# File lib/refinery/application_controller.rb, line 62
def presenter_for(model, default = BasePresenter)
  return default if model.nil?

  "#{model.class.name}Presenter".constantize
rescue NameError
  default
end