diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2007-02-25 20:13:19 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2007-02-25 20:13:19 +0000 |
commit | 784298008bf25c901564929d319eb631eb1a5639 (patch) | |
tree | 82020764784e62012d54d7da4bbc2b04f1858524 /actionpack/lib | |
parent | b203b9b55b0dc35da057cbb9b23277f60bd5260b (diff) | |
download | rails-784298008bf25c901564929d319eb631eb1a5639.tar.gz rails-784298008bf25c901564929d319eb631eb1a5639.tar.bz2 rails-784298008bf25c901564929d319eb631eb1a5639.zip |
Allow routing requirements on map.resource(s) (closes #7633) [quixoten]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6232 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_controller/resources.rb | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/actionpack/lib/action_controller/resources.rb b/actionpack/lib/action_controller/resources.rb index d55e7f02ce..d5aeaf1d45 100644 --- a/actionpack/lib/action_controller/resources.rb +++ b/actionpack/lib/action_controller/resources.rb @@ -11,7 +11,7 @@ module ActionController @singular = options[:singular] || plural.to_s.singularize @options = options - + arrange_actions add_default_actions set_prefixes @@ -21,6 +21,13 @@ module ActionController @controller ||= (options[:controller] || plural).to_s end + def requirements(with_id = false) + @requirements ||= @options[:requirements] || {} + @id_requirement ||= { :id => @requirements.delete(:id) || /[^#{Routing::SEPARATORS.join}]+/ } + + with_id ? @requirements.merge(@id_requirement) : @requirements + end + def path @path ||= "#{path_prefix}/#{plural}" end @@ -389,14 +396,14 @@ module ActionController def action_options_for(action, resource, method = nil) default_options = { :action => action.to_s } - require_id = resource.kind_of?(SingletonResource) ? {} : { :requirements => { :id => Regexp.new("[^#{Routing::SEPARATORS.join}]+") } } + require_id = !resource.kind_of?(SingletonResource) case default_options[:action] - when "index", "new" : default_options.merge(conditions_for(method || :get)) - when "create" : default_options.merge(conditions_for(method || :post)) - when "show", "edit" : default_options.merge(conditions_for(method || :get)).merge(require_id) - when "update" : default_options.merge(conditions_for(method || :put)).merge(require_id) - when "destroy" : default_options.merge(conditions_for(method || :delete)).merge(require_id) - else default_options.merge(conditions_for(method)) + when "index", "new" : default_options.merge(conditions_for(method || :get)).merge(resource.requirements) + when "create" : default_options.merge(conditions_for(method || :post)).merge(resource.requirements) + when "show", "edit" : default_options.merge(conditions_for(method || :get)).merge(resource.requirements(require_id)) + when "update" : default_options.merge(conditions_for(method || :put)).merge(resource.requirements(require_id)) + when "destroy" : default_options.merge(conditions_for(method || :delete)).merge(resource.requirements(require_id)) + else default_options.merge(conditions_for(method)).merge(resource.requirements) end end end |