diff options
author | Nicholas Seckar <nseckar@gmail.com> | 2005-07-14 00:13:06 +0000 |
---|---|---|
committer | Nicholas Seckar <nseckar@gmail.com> | 2005-07-14 00:13:06 +0000 |
commit | 2bd4ff11f83a44d3364e3e5ceaa17d1a10320687 (patch) | |
tree | 8bd8a3d995d1c0a06fe60137cc98d5bec1bd44ee /actionpack/lib | |
parent | 9314793239e3728a457d8048a02b334b8955dd23 (diff) | |
download | rails-2bd4ff11f83a44d3364e3e5ceaa17d1a10320687.tar.gz rails-2bd4ff11f83a44d3364e3e5ceaa17d1a10320687.tar.bz2 rails-2bd4ff11f83a44d3364e3e5ceaa17d1a10320687.zip |
Generate URLs for :action => index when :action => nil is supplied.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1826 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_controller/routing.rb | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/actionpack/lib/action_controller/routing.rb b/actionpack/lib/action_controller/routing.rb index 008e6d2164..f7d3fe3369 100644 --- a/actionpack/lib/action_controller/routing.rb +++ b/actionpack/lib/action_controller/routing.rb @@ -26,15 +26,19 @@ module ActionController end hash end - end - - class << self + def test_condition(expression, condition) case condition when String then "(#{expression} == #{condition.inspect})" when Regexp then condition = Regexp.new("^#{condition.source}$") unless /^\^.*\$$/ =~ condition.source "(#{condition.inspect} =~ #{expression})" + when Array then + conds = condition.collect do |condition| + cond = test_condition(expression, condition) + (cond[0, 1] == '(' && cond[-1, 1] == ')') ? cond : "(#{cond})" + end + "(#{conds.join(' || ')})" when true then expression when nil then "! #{expression}" else @@ -272,6 +276,7 @@ module ActionController defaults, conditions = initialize_hashes options.dup @defaults = defaults.dup configure_components(defaults, conditions) + add_default_requirements initialize_keys end @@ -324,7 +329,6 @@ module ActionController end protected - def initialize_components(path) path = path.split('/') if path.is_a? String path.shift if path.first.blank? @@ -356,6 +360,11 @@ module ActionController component.condition = conditions[component.key] if conditions.key?(component.key) end end + + def add_default_requirements + component_keys = components.collect {|c| c.key} + known[:action] ||= [nil, 'index'] unless component_keys.include? :action + end end class RouteSet #:nodoc: |