Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow a route to have :format => true #2263

Merged
merged 2 commits into from
Jul 25, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions actionpack/lib/action_dispatch/routing/mapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions actionpack/test/dispatch/mapper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions railties/guides/source/routing.textile
Original file line number Diff line number Diff line change
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
</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:
Expand Down