Class: DcApplicationController
- Inherits:
-
ActionController::Base
- Object
- ActionController::Base
- DcApplicationController
- Defined in:
- app/controllers/dc_application_controller.rb
Overview
DcApplicationControllerController holds methods which are useful for all application controllers.
Direct Known Subclasses
Instance Method Summary collapse
-
#dc_dump(*args) ⇒ Object
Writes anything passed as parameter to logger file.
-
#dc_edit_mode? ⇒ Boolean
Return true if CMS is in edit mode.
-
#dc_find_form_file(form_file) ⇒ String
Searches forms path for file_name and returns full file name or nil if not found.
-
#dc_get_site ⇒ DcSite
Determines site from url and returns site document.
-
#dc_log_visit ⇒ Object
Will write document to dc_visits collection unless visit comes from robot.
-
#dc_render_404(where_the_error_is = nil) ⇒ Object
Will render public/404.html file with some debug code includded.
-
#dc_user_has_role(role) ⇒ Boolean
Checks if user has required role.
-
#set_page_title ⇒ Object
Will set page title according to data on dc_page or dc_site.
Instance Method Details
#dc_dump(*args) ⇒ Object
Writes anything passed as parameter to logger file. Very useful for debuging strange errors.
40 41 42 43 44 |
# File 'app/controllers/dc_application_controller.rb', line 40 def dc_dump(*args) args.each do |arg| logger.debug arg.to_s end end |
#dc_edit_mode? ⇒ Boolean
Return true if CMS is in edit mode
51 52 53 |
# File 'app/controllers/dc_application_controller.rb', line 51 def dc_edit_mode? session[:edit_mode] > 1 end |
#dc_find_form_file(form_file) ⇒ String
Searches forms path for file_name and returns full file name or nil if not found.
be useful when you are extending form but want to retain same name as original form For example. You are extending dc_user form from drg_cms gem and want to retain same dc_user name. This can be done by setting drg_cms.dc_user to extend option.
122 123 124 125 126 127 128 129 130 131 132 |
# File 'app/controllers/dc_application_controller.rb', line 122 def dc_find_form_file(form_file) form_path=nil if form_file.match(/\.|\//) form_path,form_file=form_file.split(/\.|\//) end DrgCms.paths(:forms).reverse.each do |path| f = "#{path}/#{form_file}.yml" return f if File.exist?(f) and (form_path.nil? or path.to_s.match(/\/#{form_path}\//i)) end raise "Exception: Form file '#{form_file}' not found!" end |
#dc_get_site ⇒ DcSite
Determines site from url and returns site document.
‘test’ document is returned. If site has alias set then alias site document is returned.
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'app/controllers/dc_application_controller.rb', line 84 def dc_get_site() return @site if @site uri = URI.parse(request.url) @site = DcSite.find_by(name: uri.host) # Site can be aliased if @site and !@site.alias_for.blank? @site = DcSite.find_by(name: @site.alias_for) end # Development environment. Check if site with name test exists and use # alias_for as pointer to real site. if @site.nil? and ENV["RAILS_ENV"] != 'production' @site = DcSite.find_by(name: 'test') @site = DcSite.find_by(name: @site.alias_for) if @site end @site = nil if @site and !@site.active # site is disabled @site end |
#dc_log_visit ⇒ Object
Will write document to dc_visits collection unless visit comes from robot. It also sets session variable to true if robot.
152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'app/controllers/dc_application_controller.rb', line 152 def dc_log_visit() if request.env["HTTP_USER_AGENT"] and request.env["HTTP_USER_AGENT"].match(/\(.*https?:\/\/.*\)/) logger.info "ROBOT: #{Time.now.strftime('%Y.%m.%d %H:%M:%S')} id=#{@page.id} ip=#{request.remote_ip}." session[:is_robot] = true else DcVisit.create(site_id: @site.id, user_id: session[:user_id], page_id: @page.id, ip: request.remote_ip, session_id: request.[:id], time: Time.now ) end end |
#dc_render_404(where_the_error_is = nil) ⇒ Object
Will render public/404.html file with some debug code includded.
143 144 145 146 |
# File 'app/controllers/dc_application_controller.rb', line 143 def dc_render_404(where_the_error_is=nil) logger.info("Error 404;#{request.env['REQUEST_URI'] rescue ''};#{request.referer};#{where_the_error_is}") render(file: Rails.root.join('public/404.html'), status: 404) end |
#dc_user_has_role(role) ⇒ Boolean
Checks if user has required role.
67 68 69 70 71 72 |
# File 'app/controllers/dc_application_controller.rb', line 67 def dc_user_has_role(role) role = DcPolicyRole.get_role(role) return false if role.nil? or session[:user_roles].nil? # role is found in user_roles session[:user_roles].include?(role._id) end |
#set_page_title ⇒ Object
Will set page title according to data on dc_page or dc_site
Sets internal @page_title variable.
107 108 109 110 |
# File 'app/controllers/dc_application_controller.rb', line 107 def set_page_title() @page_title = @page.title.blank? ? @page.subject : @page.title (:name, 'description', @page.) end |