diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2004-12-12 16:14:20 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2004-12-12 16:14:20 +0000 |
commit | 8e1f1ee44241838c2b701ad2622d98c9c41ea268 (patch) | |
tree | 2e9613082d40152c0303f5b95bdd238cd7a1b36f | |
parent | b141bdbb32cb58e493e6f52e4f1baa2a9d28680d (diff) | |
download | rails-8e1f1ee44241838c2b701ad2622d98c9c41ea268.tar.gz rails-8e1f1ee44241838c2b701ad2622d98c9c41ea268.tar.bz2 rails-8e1f1ee44241838c2b701ad2622d98c9c41ea268.zip |
Moved require_association to associations.rb and added methods for resetting the inheritable attributes on subclasses
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@125 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r-- | actionpack/CHANGELOG | 2 | ||||
-rw-r--r-- | actionpack/lib/action_controller/support/class_inheritable_attributes.rb | 4 | ||||
-rwxr-xr-x | activerecord/lib/active_record/associations.rb | 20 | ||||
-rwxr-xr-x | activerecord/lib/active_record/base.rb | 32 | ||||
-rw-r--r-- | activerecord/lib/active_record/support/class_inheritable_attributes.rb | 7 | ||||
-rw-r--r-- | railties/README | 12 | ||||
-rw-r--r-- | railties/doc/index.html | 4 | ||||
-rw-r--r-- | railties/lib/dispatcher.rb | 8 | ||||
-rw-r--r-- | railties/lib/webrick_server.rb | 25 |
9 files changed, 59 insertions, 55 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 05569a2c06..a8fa53a143 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Added display of error messages with scaffolded form pages + * Added option to ERB templates to swallow newlines by using <% if something -%> instead of just <% if something %>. Example: class SomeController < AbstractApplicationController diff --git a/actionpack/lib/action_controller/support/class_inheritable_attributes.rb b/actionpack/lib/action_controller/support/class_inheritable_attributes.rb index 7f061fdf1b..39312e8d5b 100644 --- a/actionpack/lib/action_controller/support/class_inheritable_attributes.rb +++ b/actionpack/lib/action_controller/support/class_inheritable_attributes.rb @@ -28,6 +28,10 @@ module ClassInheritableAttributes # :nodoc: inheritable_attributes[key] end + def reset_inheritable_attributes + inheritable_attributes.clear + end + private def inherited(child) @@classes[child] = inheritable_attributes.dup diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 6f6da10a01..6ba7b80102 100755 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -3,6 +3,10 @@ require 'active_record/associations/has_many_association' require 'active_record/associations/has_and_belongs_to_many_association' require 'active_record/deprecated_associations' +unless Object.respond_to?(:require_association) + Object.send(:define_method, :require_association) { |file_name| ActiveRecord::Base.require_association(file_name) } +end + module ActiveRecord module Associations # :nodoc: def self.append_features(base) @@ -447,6 +451,20 @@ module ActiveRecord deprecated_has_collection_method(association_name) end + # Loads the <tt>file_name</tt> if reload_associations is true or requires if it's false. + def require_association(file_name) + if !associations_loaded.include?(file_name) + associations_loaded << file_name + reload_associations ? silence_warnings { load("#{file_name}.rb") } : require(file_name) + end + end + + # Resets the list of dependencies loaded (typically to be called by the end of a request), so when require_association is + # called for that dependency it'll be loaded anew. + def reset_associations_loaded + associations_loaded = [] + end + private # Raises an exception if an invalid option has been specified to prevent misspellings from slipping through def validate_options(valid_option_keys, supplied_option_keys) @@ -571,4 +589,4 @@ module ActiveRecord end end end -end +end
\ No newline at end of file diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 2346aa19e9..465a1ed8cf 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -3,10 +3,6 @@ require 'active_record/support/class_inheritable_attributes' require 'active_record/support/inflector' require 'yaml' -unless Object.respond_to?(:require_association) - Object.send(:define_method, :require_association) { |file_name| ActiveRecord::Base.require_association(file_name) } -end - module ActiveRecord #:nodoc: class ActiveRecordError < StandardError #:nodoc: end @@ -192,6 +188,10 @@ module ActiveRecord #:nodoc: end @@subclasses = {} + + def self.subclasses + @@subclasses.values.flatten + end cattr_accessor :configurations @@primary_key_prefix_type = {} @@ -559,20 +559,6 @@ module ActiveRecord #:nodoc: return result end - # Loads the <tt>file_name</tt> if reload_associations is true or requires if it's false. - def require_association(file_name) - if !associations_loaded.include?(file_name) - associations_loaded << file_name - reload_associations ? silence_warnings { load("#{file_name}.rb") } : require(file_name) - end - end - - # Resets the list of dependencies loaded (typically to be called by the end of a request), so when require_association is - # called for that dependency it'll be loaded anew. - def reset_associations_loaded - associations_loaded = [] - end - private # Finder methods must instantiate through this method to work with the single-table inheritance model # that makes it possible to create objects of different types from the same table. @@ -840,16 +826,6 @@ module ActiveRecord #:nodoc: def respond_to?(method) self.class.column_methods_hash[method.to_sym] || respond_to_without_attributes?(method) end - - # Loads the <tt>file_name</tt> if reload_associations is true or requires if it's false. - def require_association(file_name) - if !associations_loaded.include?(file_name) - associations_loaded << file_name - reload_associations ? silence_warnings { load("#{file_name}.rb") } : require(file_name) - end - end - - Object.send(:define_method, :require_association) { |file_name| ActiveRecord::Base.require_association(file_name) } private def create_or_update diff --git a/activerecord/lib/active_record/support/class_inheritable_attributes.rb b/activerecord/lib/active_record/support/class_inheritable_attributes.rb index ee69646da0..201932cf2d 100644 --- a/activerecord/lib/active_record/support/class_inheritable_attributes.rb +++ b/activerecord/lib/active_record/support/class_inheritable_attributes.rb @@ -28,10 +28,13 @@ module ClassInheritableAttributes # :nodoc: inheritable_attributes[key] end + def reset_inheritable_attributes + inheritable_attributes.clear + end + private def inherited(child) @@classes[child] = inheritable_attributes.dup - end - + end end end diff --git a/railties/README b/railties/README index 4702f8a6c8..c8446e4e55 100644 --- a/railties/README +++ b/railties/README @@ -34,15 +34,13 @@ link:files/vendor/actionpack/README.html. * Apache 1.3.x or 2.x (or any FastCGI-capable webserver with a mod_rewrite-like module) -* FastCGI (or mod_ruby) for production performance (CGI is used for - development) +* FastCGI (or mod_ruby) for better performance on Apache == Getting started -1a. Setup Apache for the Rails application (see "Example for Apache conf") -1b. Run the WEBrick servlet: <tt>ruby public/dispatch.servlet --help</tt> -2. Go to http://rails/ (or whatever is your ServerName) and check - that you get the "Congratulations, you're on Rails!" screen +1. Run the WEBrick servlet: <tt>ruby public/dispatch.servlet</tt> + (run with --help for options) +2. Go to http://localhost:3000/ and get "Congratulations, you've put Ruby on Rails!" 3. Follow the guidelines on the "Congratulations, you're on Rails!" screen @@ -50,7 +48,7 @@ link:files/vendor/actionpack/README.html. <VirtualHost *:80> ServerName rails - DocumentRoot /path/tapplication/public/ + DocumentRoot /path/application/public/ ErrorLog /path/application/log/apache.log <Directory /path/application/public/> diff --git a/railties/doc/index.html b/railties/doc/index.html index b40b9562ea..522a88cd5c 100644 --- a/railties/doc/index.html +++ b/railties/doc/index.html @@ -53,8 +53,8 @@ <small>Recommendation: Use *_development and *_test names, such as basecamp_development and basecamp_test</small><br/> <small>Warning: Don't point your test database at your development database, it'll destroy the latter on test runs!</small> <li>Edit config/database.yml with your database settings. - <li>Create controllers and models using the generators in <code>script/new_*</code> <br/> - <small>Help: Run a generator with no arguments for documentation</small> + <li>Create controllers and models using the generator in <code>script/generate</code> <br/> + <small>Help: Run the generator with no arguments for documentation</small> <li>See all the tests run by running <code>rake</code>. <li>Develop your Rails application! <li>Setup Apache with <a href="http://www.fastcgi.com">FastCGI</a> (and <a href="http://raa.ruby-lang.org/list.rhtml?name=fcgi">Ruby bindings</a>), if you need better performance diff --git a/railties/lib/dispatcher.rb b/railties/lib/dispatcher.rb index 680b03fb42..0cb76ad104 100644 --- a/railties/lib/dispatcher.rb +++ b/railties/lib/dispatcher.rb @@ -22,7 +22,7 @@ #++ class Dispatcher - DEFAULT_SESSION_OPTIONS = { "database_manager" => CGI::Session::PStore, "prefix" => "ruby_sess.", "session_path" => "/" } + DEFAULT_SESSION_OPTIONS = { :database_manager => CGI::Session::PStore, :prefix => "ruby_sess.", :session_path => "/" } def self.dispatch(cgi = CGI.new, session_options = DEFAULT_SESSION_OPTIONS) begin @@ -38,12 +38,12 @@ class Dispatcher rescue Object => exception ActionController::Base.process_with_exception(request, response, exception).out ensure - ActiveRecord::Base.reset_associations_loaded - if ActionController::Base.reload_dependencies Object.send(:remove_const, "AbstractApplicationController") if Object.const_defined?(:AbstractApplicationController) Object.send(:remove_const, controller_class_name(controller_name)) if Object.const_defined?(controller_class_name(controller_name)) - end + ActiveRecord::Base.reset_associations_loaded + ActiveRecord::Base.subclasses.each { |klass| klass.reset_inheritable_attributes } + end end end diff --git a/railties/lib/webrick_server.rb b/railties/lib/webrick_server.rb index 885610d9a0..698ac3cbbf 100644 --- a/railties/lib/webrick_server.rb +++ b/railties/lib/webrick_server.rb @@ -50,7 +50,7 @@ class DispatchServlet < WEBrick::HTTPServlet::AbstractServlet if @server_options[:index_controller] res.set_redirect WEBrick::HTTPStatus::MovedPermanently, "/#{@server_options[:index_controller]}/" else - res.set_redirect WEBrick::HTTPStatus::MovedPermanently, "/_doc/index.html" + res.set_redirect WEBrick::HTTPStatus::MovedPermanently, "/_doc/" end return true @@ -72,9 +72,8 @@ class DispatchServlet < WEBrick::HTTPServlet::AbstractServlet end def handle_mapped(req, res) - parsed_ok, controller, action, id = DispatchServlet.parse_uri(req.request_uri.path) - if parsed_ok - query = "controller=#{controller}&action=#{action}&id=#{id}" + if mappings = DispatchServlet.parse_uri(req.request_uri.path) + query = mappings.collect { |pair| "#{pair.first}=#{pair.last}" }.join("&") query << "&#{req.request_uri.query}" if req.request_uri.query origin = req.request_uri.path + "?" + query req.request_uri.path = "/dispatch.rb" @@ -124,17 +123,21 @@ class DispatchServlet < WEBrick::HTTPServlet::AbstractServlet end def self.parse_uri(path) - component = /([-_a-zA-Z0-9]+)/ + component, id = /([-_a-zA-Z0-9]+)/, /([0-9]+)/ case path.sub(%r{^/(?:fcgi|mruby|cgi)/}, "/") when %r{^/#{component}/?$} then - [true, $1, "index", nil] - when %r{^/#{component}/#{component}/?$} then - [true, $1, $2, nil] - when %r{^/#{component}/#{component}/#{component}/?$} then - [true, $1, $2, $3] + { :controller => $1, :action => "index" } + when %r{^/#{component}/#{component}$} then + { :controller => $1, :action => $2 } + when %r{^/#{component}/#{component}/$} then + { :module => $1, :controller => $2, :action => "index" } + when %r{^/#{component}/#{component}/#{id}$} then + { :controller => $1, :action => $2, :id => $3 } + when %r{^/#{component}/#{component}/#{component}/#{id}$} then + { :module => $1, :controller => $2, :action => $3, :id => $4 } else - [false, nil, nil, nil] + false end end end |