Skip to content

Commit

Permalink
Merge pull request #2262 from sferik/format_true
Browse files Browse the repository at this point in the history
Allow a route to have :format => true
  • Loading branch information
josevalim committed Jul 25, 2011
2 parents cb85d70 + c172543 commit 647eeb1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions actionpack/lib/action_dispatch/routing/mapper.rb
Expand Up @@ -119,6 +119,8 @@ def normalize_path(path)
path path
elsif path.include?(":format") || path.end_with?('/') elsif path.include?(":format") || path.end_with?('/')
path path
elsif @options[:format] == true
"#{path}.:format"
else else
"#{path}(.:format)" "#{path}(.:format)"
end end
Expand Down
7 changes: 7 additions & 0 deletions actionpack/test/dispatch/mapper_test.rb
Expand Up @@ -83,6 +83,13 @@ def test_map_wildcard_with_format_false
assert_equal '/*path', fakeset.conditions.first[:path_info] assert_equal '/*path', fakeset.conditions.first[:path_info]
assert_nil fakeset.requirements.first[:path] assert_nil fakeset.requirements.first[:path]
end 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 end
end end
6 changes: 6 additions & 0 deletions railties/guides/source/routing.textile
Expand Up @@ -569,6 +569,12 @@ NOTE: By requesting +"/foo/bar.json"+, your +params[:pages]+ will be equals to +
match '*pages' => 'pages#show', :format => false match '*pages' => 'pages#show', :format => false
</ruby> </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 h4. Redirection


You can redirect any path to another path using the +redirect+ helper in your router: You can redirect any path to another path using the +redirect+ helper in your router:
Expand Down

0 comments on commit 647eeb1

Please sign in to comment.