Module: Refinery::ApplicationController

Included in:
AdminController, Pages::Admin::PreviewController
Defined in:
core/lib/refinery/application_controller.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

Extend controller



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'core/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

Instance Method Details

#admin?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'core/lib/refinery/application_controller.rb', line 26

def admin?
  %r{\Aadmin/} === controller_name
end

#current_refinery_userObject



50
51
52
# File 'core/lib/refinery/application_controller.rb', line 50

def current_refinery_user
  authorisation_manager.current_user
end

#error_404(exception = nil) ⇒ Object



30
31
32
33
34
35
36
# File 'core/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, format: :html, layout: false, status: 404
  return false
end

#from_dialog?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'core/lib/refinery/application_controller.rb', line 38

def from_dialog?
  params[:dialog] == 'true' || params[:modal] == 'true'
end

#home_page?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'core/lib/refinery/application_controller.rb', line 42

def home_page?
  %r{^#{Regexp.escape(request.path)}} === refinery.root_path
end

#local_request?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'core/lib/refinery/application_controller.rb', line 46

def local_request?
  Rails.env.development? || /(::1)|(127.0.0.1)|((192.168).*)/ === request.remote_ip
end