From 2bd4ff11f83a44d3364e3e5ceaa17d1a10320687 Mon Sep 17 00:00:00 2001 From: Nicholas Seckar Date: Thu, 14 Jul 2005 00:13:06 +0000 Subject: 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 --- actionpack/lib/action_controller/routing.rb | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'actionpack/lib') 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: -- cgit v1.2.3