class ApplicationController < ActionController::Base session :session_key => '_Intranet_session_id' protected def local_request? false end protected def rescue_action_in_public(exception) if exception.is_a?(ActiveRecord::RecordNotFound) @message = "Record not found" elsif exception.is_a?(::ActionController::UnknownAction) or exception.is_a?(::ActionController::RoutingError) @message = "Page not found" else @message = "The application is not currently available" end render :template => 'shared/exception' end protected def authorize unless (true == session[:logged_in]) session[:destination] = request.request_uri redirect_to :controller => 'login' return false end end # Set +message+ under the :notice key in the flash, # then redirect to the index action. private def redirect_to_index(message=nil) flash[:notice] = message redirect_to :action => 'index' end private def confirm_delete(object, prompt) @object = object @page_title = prompt render :template => 'shared/confirm' end private def do_delete(object, redirect_options=nil) if 'yes' == params[:confirm] object.destroy object_name = object.class.name.humanize flash[:notice] = object_name + ' deleted successfully' redirect_options ||= {:action => 'index'} redirect_to redirect_options end end protected def local_request? false end if DEFINE_PROFILER # A class which can be used as an around_filter for a controller, # to profile actions on that controller; profiles get # written into the profile directory with the # filename '_.txt' class ProfileFilter require 'profile' # Extend the ProfileFilter class with methods from the # Profiler__ class extend Profiler__ # The filter class method must be implemented to # employ this class as a filter private def self.filter(controller, &action) start_profile action.call stop_profile profile_file_name = controller.controller_name.to_s + '_' \ + controller.action_name.to_s + '.txt' out = File.open( File.join(RAILS_ROOT, 'profile', profile_file_name), 'w' ) print_profile(out) end end end # Store a fragment in the cache; "." + fragment_suffix is # appended to the standard cache key for this # controller/action; if a fragment with this key exists, # return it; if not, call the block &generator to create # the value, store it in the cache, and return it private def handle_text_fragment(fragment_suffix, &generator) text_fragment_name = fragment_cache_key({}) + "." + fragment_suffix value = read_fragment(text_fragment_name) unless value begin value = generator.call write_fragment(text_fragment_name, value) rescue value = '' end end return value end protected # Adds apostrophe to text for SQL LIKE statement. # prep_for_like('search') > '%search%' # prep_for_like('search', 'start') > 'search%' # prep_for_like('search', 'match') > 'search' def prep_for_like(text, placement='contain') case placement when 'match' text when 'start' "#{text}%" when 'end' "%#{text}" else "%#{text}%" end end end