Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #2263 from sferik/format_true

Allow a route to have :format => true
  • Loading branch information...
commit 19a3c9b41c90aa65855fb72a94face37168f5fd7 2 parents 05503f1 + 78d151d
@josevalim josevalim authored
View
2  actionpack/lib/action_dispatch/routing/mapper.rb
@@ -116,6 +116,8 @@ def normalize_path(path)
path
elsif path.include?(":format") || path.end_with?('/')
path
+ elsif @options[:format] == true
+ "#{path}.:format"
else
"#{path}(.:format)"
end
View
7 actionpack/test/dispatch/mapper_test.rb
@@ -83,6 +83,13 @@ def test_map_wildcard_with_format_false
assert_equal '/*path', fakeset.conditions.first[:path_info]
assert_nil fakeset.requirements.first[:path]
end
+
+ def test_map_wildcard_with_format_true
+ fakeset = FakeSet.new
+ mapper = Mapper.new fakeset
+ mapper.match '/*path', :to => 'pages#show', :format => true
+ assert_equal '/*path.:format', fakeset.conditions.first[:path_info]
+ end
end
end
end
View
6 railties/guides/source/routing.textile
@@ -569,6 +569,12 @@ NOTE: By requesting +"/foo/bar.json"+, your +params[:pages]+ will be equals to +
match '*pages' => 'pages#show', :format => false
</ruby>
+NOTE: If you want to make the format segment mandatory, so it cannot be omitted, you can supply +:format => true+ like this:
+
+<ruby>
+match '*pages' => 'pages#show', :format => true
+</ruby>
+
h4. Redirection
You can redirect any path to another path using the +redirect+ helper in your router:
Please sign in to comment.
Something went wrong with that request. Please try again.