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

Changeset 817

Show
Ignore:
Timestamp:
03/01/05 02:04:54 (4 years ago)
Author:
david
Message:

Fix request.path_info and clear up LoadingModule behavior #754 [Nicholas Seckar]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/lib/action_controller/request.rb

    r802 r817  
    7979 
    8080    def path_info 
    81       env['PATH_INFO'] 
     81      (/^(.*)\.html$/ =~ env['PATH_INFO']) ? $1 : env['PATH_INFO'] 
    8282    end 
    8383 
  • trunk/actionpack/test/controller/request_test.rb

    r802 r817  
    5959    assert_equal "/path/of/some/uri", @request.path_info 
    6060    assert_equal "/path/of/some/uri", @request.path 
     61     
     62    # PATH_INFO actually has a .html suffix on many servers. But we don't want Rails to see the .html part. 
     63    @request.env["PATH_INFO"] = "/path/of/some/uri.html" 
     64    assert_equal "/path/of/some/uri", @request.path_info 
     65    assert_equal "/path/of/some/uri", @request.path 
    6166  end 
    6267 
  • trunk/activesupport/lib/active_support/dependencies.rb

    r718 r817  
    3737   
    3838  def require_or_load(file_name) 
    39     load? ? load("#{file_name}.rb") : require(file_name) 
     39    file_name = "#{file_name}.rb" unless ! load? || /\.rb$/ =~ file_name 
     40    load? ? load(file_name) : require(file_name) 
    4041  end 
    4142   
     
    6364    end 
    6465     
     66    def root?() self.root == self end 
    6567    def load_paths() self.root.load_paths end 
    6668     
     
    7981 
    8082        if File.directory?(fs_path) 
    81           self.const_set name, LoadingModule.new(self.root, self.path + [name]) 
     83          new_module = LoadingModule.new(self.root, self.path + [name]) 
     84          self.const_set name, new_module 
     85          if self.root? 
     86            raise NameError, "Cannot load controller module named #{name}: An object of type #{Object.const_get(name).class.to_s} already exists." \ 
     87              if Object.const_defined?(name) 
     88            Object.const_set(name, new_module)  
     89          end 
    8290          break 
    8391        elsif File.file?(fs_path) 
    8492          self.root.load_file!(fs_path) 
     93           
     94          # Import the loaded constant from Object provided we are the root node. 
     95          self.const_set(name, Object.const_get(name)) if self.root? && Object.const_defined?(name) 
    8596          break 
    8697        end 
     
    110121    # Load the source file at the given file path 
    111122    def load_file!(file_path) 
    112       begin root.module_eval(IO.read(file_path), file_path, 1) 
    113       rescue Object => exception 
    114         exception.blame_file! file_path 
    115         raise 
    116       end 
     123      require_dependency(file_path) 
    117124    end 
    118125 
     
    120127    def clear! 
    121128      constants.each do |name| 
    122         Object.send(:remove_const, name) if Object.const_defined?(name) && self.path.empty? 
     129        Object.send(:remove_const, name) if Object.const_defined?(name) 
    123130        self.send(:remove_const, name) 
    124131      end