Class: ApplicationController
- Inherits:
-
ActionController::Base
- Object
- ActionController::Base
- ApplicationController
- Defined in:
- app/controllers/application.rb
Overview
Filters added to this controller apply to all controllers in the application. Likewise, all the methods added will be available for all controllers.
Direct Known Subclasses
JsHelperController, LinkRouterController, OpenSearchController, ResolveController, ResourceController, SearchController, StoreController
Instance Method Summary (collapse)
- - (Object) app_before_filter
- - (Object) calculate_url_for_response(svc_type)
-
- (Object) error_404
Just returns a generic 404 page.
-
- (Object) escape_xml(string)
Just replaces , &, ', and " so you can include arbitrary text as an xml payload.
- - (Object) frameset_action_url(svc_type, extra_params = {})
-
- (Object) log_error(exception)
Over-ride to keep routing error backtraces out of our logs, and log them special.
-
- (Object) log_processing
Over-ride the log processing method to include referrer logging,useful for debugging.
-
- (Object) params_preserve_xhr(my_params = params)
if it's an xml-http-request, and we're redirecting to ourselves...
-
- (Object) rescue_action_in_public(exception)
Default error page.
- - (Object) url_for_with_co(params, context_object)
Instance Method Details
- (Object) app_before_filter
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/controllers/application.rb', line 48 def app_before_filter @use_umlaut_journal_index = AppConfig.param("use_umlaut_journal_index", true) # We have an apache redir workaround to fix EBSCO illegal URLs. # But it ends up turning all "&" to "&" as seperators in # query portion of url. # which makes rails add all these weird request params named 'amp' or # 'amp;[something]'. Along with, strangely, the 'correct' params too. # So we strip the weird ones out. if ( request.query_string =~ /\&\;/) params.keys.each do |param| params.delete( param ) if param == 'amp' || param =~ /^amp\;/ end end return true end |
- (Object) calculate_url_for_response(svc_type)
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'app/controllers/application.rb', line 159 def calculate_url_for_response(svc_type) svc = ServiceList.instance.instantiate!(svc_type.service_response.service_id, @user_request) destination = svc.response_url(svc_type, params) # if response_url returned a string, it's an external url and we're # done. If it's something else, usually a hash, then pass it to # url_for to generate a url. if destination.kind_of?(String) url = destination # Call link_out_filters, if neccesary. # These are services listed as task: link_out_filter in services.yml (1..9).each do |priority| @collection.link_out_service_level( priority ).each do |filter| filtered_url = filter.link_out_filter(url, svc_type) url = filtered_url if filtered_url end end return url else return url_for(params_preserve_xhr(destination)) end end |
- (Object) error_404
Just returns a generic 404 page. Other people can redirect here if desired. Uses generic 404 page already stored in public/404.html as rails convention.
69 70 71 |
# File 'app/controllers/application.rb', line 69 def error_404 render :file=>File.join(RAILS_ROOT,"public/404.html"), :layout=>false, :status=>404 end |
- (Object) escape_xml(string)
Just replaces <, >, &, ', and " so you can include arbitrary text as an xml payload. I think those three chars are all you need for an xml escape. Weird this isn't built into Rails, huh?
112 113 114 115 116 117 118 119 120 121 122 |
# File 'app/controllers/application.rb', line 112 def escape_xml(string) string.gsub(/[&<>\'\"]/) do | match | case match when '&' then '&' when '<' then '<' when '>' then '>' when '"' then '"' when "'" then ''' end end end |
- (Object) frameset_action_url(svc_type, extra_params = {})
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'app/controllers/application.rb', line 89 def frameset_action_url(svc_type, extra_params = {}) u_request = svc_type.request # Start with a nice context object original_co = u_request.to_context_object # Add our controller code and id references # We use 'umlaut.id' instead of just 'id' as a param to avoid # overwriting an OpenURL 0.1 'id' param! params= { :controller=>'resolve', :action=>'bannered_link_frameset', :umlaut.request_id' => u_request.id, :umlaut.id'=>svc_type.id} params.merge!(extra_params) return url_for_with_co(params, original_co) end |
- (Object) log_error(exception)
Over-ride to keep routing error backtraces out of our logs, and log them special.
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/controllers/application.rb', line 34 def log_error(exception) unless ( exception.kind_of?(::ActionController::RoutingError) || exception.kind_of?(::ActionController::UnknownAction) || exception.kind_of?(::ActionController::UnknownController)) super(exception) else logger.warn("\n\n#{exception.class} (#{exception.}):\n" + " Request uri: #{request.request_uri} \n" + " User-agent: #{request.headers['User-Agent']}\n" + " Referer: #{request.headers['Referer']}\n") end end |
- (Object) log_processing
Over-ride the log processing method to include referrer logging,useful for debugging.
75 76 77 78 79 80 81 82 83 |
# File 'app/controllers/application.rb', line 75 def log_processing super if logger && logger.info? logger.info(" HTTP Referer: #{request.referer}") if request && request.referer logger.info(" HTTP Referer: [none]") unless request && request.referer logger.info(" User-Agent: #{request.user_agent}") end end |
- (Object) params_preserve_xhr(my_params = params)
if it's an xml-http-request, and we're redirecting to ourselves... afraid we're going to lost the X-Requested-With header on redirect, messing up our Rails code. Add it as a query param, sorry weird workaround.
188 189 190 191 192 193 194 |
# File 'app/controllers/application.rb', line 188 def params_preserve_xhr(my_params = params) if request.xml_http_request? my_params = my_params.clone my_params["X-Requested-With"] = "XmlHttpRequest" end my_params end |
- (Object) rescue_action_in_public(exception)
Default error page. Individual controllers can over-ride.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/controllers/application.rb', line 13 def rescue_action_in_public(exception) status = 500 @page_title = "Error!" # Weird way to specify class names. See. #http://dev.rubyonrails.org/ticket/6863 if ( exception.kind_of?(::ActionController::RoutingError) || exception.kind_of?(::ActionController::UnknownAction) || exception.kind_of?(::ActionController::UnknownController)) # UnknownController # url that didn't match. It's a 404 error. status = 404 @page_title = "Not Found!" @not_found_error = true end # search error works. render :template => "error/search_error", :status=>status, :layout=>AppConfig.param("search_layout","search_basic") end |
- (Object) url_for_with_co(params, context_object)
133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'app/controllers/application.rb', line 133 def url_for_with_co(params, context_object) url = url_for(params) if (url.include?('?')) url += '&' else url += '?' end url += context_object.kev return url end |