提交 8c7e8976 编写于 作者: D Diego Carrion 提交者: Jeremy Kemper

added shorthand support for routes like /projects/status(.:format)

Signed-off-by: NJeremy Kemper <jeremy@bitsweat.net>
上级 afcd2522
*Rails 3.0.0 [beta 4/release candidate] (unreleased)*
* Add support for shorthand routes like /projects/status(.:format) #4423 [Diego Carrion]
* Changed translate helper so that it doesnt mark every translation as safe HTML. Only keys with a "_html" suffix and keys named "html" are considered to be safe HTML. All other translations are left untouched. [Craig Davey]
......
......@@ -66,8 +66,8 @@ def extract_path_and_options(args)
path = normalize_path(path)
if using_match_shorthand?(path, options)
options[:to] ||= path[1..-1].sub(%r{/([^/]*)$}, '#\1')
options[:as] ||= path[1..-1].gsub("/", "_")
options[:to] ||= path[1..-1].sub(%r{/([^/]*)$}, '#\1').sub(%r{\(.*\)}, '')
options[:as] ||= path[1..-1].gsub("/", "_").sub(%r{\(.*\)}, '')
end
[ path, options ]
......@@ -80,7 +80,7 @@ def using_to_shorthand?(args, options)
# match "account/overview"
def using_match_shorthand?(path, options)
path && options.except(:via, :anchor, :to, :as).empty? && path =~ %r{^/[\w\/]+$}
path && options.except(:via, :anchor, :to, :as).empty? && path =~ %r{^/[\w+/?]+(\(.*\))*$}
end
def normalize_path(path)
......
......@@ -54,6 +54,8 @@ def self.matches?(request)
match "/local/:action", :controller => "local"
match "/projects/status(.:format)"
constraints(:ip => /192\.168\.1\.\d\d\d/) do
get 'admin' => "queenbee#index"
end
......@@ -426,6 +428,13 @@ def test_local
end
end
def test_projects_status
with_test_routes do
assert_equal '/projects/status', url_for(:controller => 'projects', :action => 'status', :only_path => true)
assert_equal '/projects/status.json', url_for(:controller => 'projects', :action => 'status', :format => 'json', :only_path => true)
end
end
def test_projects
with_test_routes do
get '/projects'
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册