Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #8582: per_request_view_paths.diff

File per_request_view_paths.diff, 3.0 kB (added by dasil003, 2 years ago)

The Fix

  • actionpack/lib/action_view/base.rb

    old new  
    156156    attr_accessor :base_path, :assigns, :template_extension 
    157157    attr_accessor :controller 
    158158 
    159     attr_reader :logger, :response, :headers, :view_paths 
     159    attr_reader :logger, :response, :headers 
    160160    attr_internal :cookies, :flash, :headers, :params, :request, :response, :session 
    161161     
    162162    attr_writer :template_format 
     
    267267        else 
    268268          template_extension = pick_template_extension(template_path).to_s 
    269269          unless template_extension 
    270             raise ActionViewError, "No #{template_handler_preferences.to_sentence} template found for #{template_path} in #{@view_paths.inspect}" 
     270            raise ActionViewError, "No #{template_handler_preferences.to_sentence} template found for #{template_path} in #{view_paths.inspect}" 
    271271          end 
    272272          template_file_name = full_template_path(template_path, template_extension) 
    273273          template_extension = template_extension.gsub(/^\w+\./, '') # strip off any formats 
     
    279279      template_source = nil # Don't read the source until we know that it is required 
    280280 
    281281      if template_file_name.blank? 
    282         raise ActionViewError, "Couldn't find template file for #{template_path} in #{@view_paths.inspect}" 
     282        raise ActionViewError, "Couldn't find template file for #{template_path} in #{view_paths.inspect}" 
    283283      end 
    284284 
    285285      begin 
     
    293293        end 
    294294      end 
    295295    end 
    296      
     296 
    297297    # Renders the template present at <tt>template_path</tt> (relative to the view_paths array).  
    298298    # The hash in <tt>local_assigns</tt> is made available as local variables. 
    299299    def render(options = {}, old_local_assigns = {}, &block) #:nodoc: 
     
    432432      TEMPLATE_HANDLER_PREFERENCES[template_format] || DEFAULT_TEMPLATE_HANDLER_PREFERENCE 
    433433    end 
    434434 
     435    def view_paths 
     436      if @controller 
     437        @controller.view_paths 
     438      else 
     439        @view_paths 
     440      end 
     441    end 
     442     
    435443    private 
    436444      def find_full_template_path(template_path, extension) 
    437445        file_name = "#{template_path}.#{extension}" 
     
    450458        template_path_without_extension = template_path.sub(/\.(\w+)$/, '') 
    451459        [ template_path_without_extension, $1 ] 
    452460      end 
    453        
     461 
    454462      # Returns the view path that contains the given relative template path. 
    455463      def find_base_path_for(template_file_name) 
    456         @view_paths.find { |p| File.file?(File.join(p, template_file_name)) } 
     464        view_paths.find { |p| File.file?(File.join(p, template_file_name)) } 
    457465      end 
    458466 
    459467      # Returns the view path that the full path resides in. 
    460468      def extract_base_path_from(full_path) 
    461         @view_paths.find { |p| full_path[0..p.size - 1] == p } 
     469        view_paths.find { |p| full_path[0..p.size - 1] == p } 
    462470      end 
    463471 
    464472      # Determines the template's file extension, such as rhtml, rxml, or rjs.