Permalink
Browse files

Added that controllers will now attempt to require a model dependency…

… with their name and in a singular attempt for their name.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@175 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 1579f3b commit 8bc82278dddfe23d84ac24ffe83f92c816028dd8 @dhh dhh committed Dec 16, 2004
Showing with 16 additions and 0 deletions.
  1. +4 −0 actionpack/CHANGELOG
  2. +12 −0 actionpack/lib/action_controller/dependencies.rb
View
@@ -1,5 +1,9 @@
*SVN*
+* Added that controllers will now attempt to require a model dependency with their name and in a singular attempt for their name.
+ So both PostController and PostsController will automatically have the post.rb model required. If no model is found, no error is raised,
+ as it is then expected that no match is available and the programmer will have included his own models.
+
* Fixed DateHelper#date_select so that you can pass include_blank as an option even if you don't use start_year and end_year #59 [what-a-day]
* Added that controllers will now search for a layout in $template_root/layouts/$controller_name.r(html|xml), so PostsController will look
@@ -15,6 +15,8 @@ def self.append_features(base)
cattr_accessor :reload_dependencies
end
+ base.class_eval { class << self; alias_method :inherited_without_model, :inherited; end }
+
base.extend(ClassMethods)
end
@@ -62,6 +64,16 @@ def require_dependencies(layer, dependencies)
end
end
end
+
+ def inherited(child)
+ inherited_without_model(child)
+ begin
+ child.model(child.controller_name)
+ child.model(Inflector.singularize(child.controller_name))
+ rescue LoadError
+ # No neither singular or plural model available for this controller
+ end
+ end
end
end
end

0 comments on commit 8bc8227

Please sign in to comment.