Skip to content
This repository
Browse code

Allow a route to have :format => true

When format is true, it is mandatory (as opposed to :format => false).
This is currently not possible with resource routes, which automatically
make format optional by default.
  • Loading branch information...
commit c41ecd7164d4eda0daa62aea1f7dbe71d3e8a921 1 parent 05503f1
Erik Michaels-Ober authored July 25, 2011
2  actionpack/lib/action_dispatch/routing/mapper.rb
@@ -116,6 +116,8 @@ def normalize_path(path)
116 116
               path
117 117
             elsif path.include?(":format") || path.end_with?('/')
118 118
               path
  119
+            elsif @options[:format] == true
  120
+              "#{path}.:format"
119 121
             else
120 122
               "#{path}(.:format)"
121 123
             end
7  actionpack/test/dispatch/mapper_test.rb
@@ -83,6 +83,13 @@ def test_map_wildcard_with_format_false
83 83
         assert_equal '/*path', fakeset.conditions.first[:path_info]
84 84
         assert_nil fakeset.requirements.first[:path]
85 85
       end
  86
+
  87
+      def test_map_wildcard_with_format_true
  88
+        fakeset = FakeSet.new
  89
+        mapper = Mapper.new fakeset
  90
+        mapper.match '/*path', :to => 'pages#show', :format => true
  91
+        assert_equal '/*path.:format', fakeset.conditions.first[:path_info]
  92
+      end
86 93
     end
87 94
   end
88 95
 end

0 notes on commit c41ecd7

Please sign in to comment.
Something went wrong with that request. Please try again.