Module: Refinery::ApplicationController

Included in:
AdminController
Defined in:
lib/refinery/application_controller.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

Extend controller



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/refinery/application_controller.rb', line 4

def self.included(base) # Extend controller
  base.helper_method :home_page?, :local_request?, :just_installed?,
                     :from_dialog?, :admin?, :login?

  base.protect_from_forgery # 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)


20
21
22
# File 'lib/refinery/application_controller.rb', line 20

def admin?
  %r{^admin/} === controller_name
end

#error_404(exception = nil) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/refinery/application_controller.rb', line 24

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?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/refinery/application_controller.rb', line 33

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

#home_page?Boolean

Returns:

  • (Boolean)


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

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

#just_installed?Boolean

Returns:

  • (Boolean)


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

def just_installed?
  Refinery::Role[:refinery].users.empty?
end

#local_request?Boolean

Returns:

  • (Boolean)


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

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

#login?Boolean

Returns:

  • (Boolean)


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

def login?
  (/^(user|session)(|s)/ === controller_name && !admin?) || just_installed?
end