mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
No need to create a separate lambda for each call.
This commit is contained in:
parent
7b2d51817d
commit
86bcccf8df
1 changed files with 14 additions and 15 deletions
|
@ -334,6 +334,19 @@ module ActionDispatch
|
|||
end
|
||||
|
||||
class Generator #:nodoc:
|
||||
PARAMETERIZE = {
|
||||
:parameterize => lambda do |name, value|
|
||||
if name == :controller
|
||||
value
|
||||
elsif value.is_a?(Array)
|
||||
value.map { |v| Rack::Mount::Utils.escape_uri(v.to_param) }.join('/')
|
||||
else
|
||||
return nil unless param = value.to_param
|
||||
param.split('/').map { |v| Rack::Mount::Utils.escape_uri(v) }.join("/")
|
||||
end
|
||||
end
|
||||
}
|
||||
|
||||
attr_reader :options, :recall, :set, :named_route
|
||||
|
||||
def initialize(options, recall, set, extras = false)
|
||||
|
@ -422,7 +435,7 @@ module ActionDispatch
|
|||
end
|
||||
|
||||
def generate
|
||||
path, params = @set.set.generate(:path_info, named_route, options, recall, opts)
|
||||
path, params = @set.set.generate(:path_info, named_route, options, recall, PARAMETERIZE)
|
||||
|
||||
raise_routing_error unless path
|
||||
|
||||
|
@ -436,20 +449,6 @@ module ActionDispatch
|
|||
raise_routing_error
|
||||
end
|
||||
|
||||
def opts
|
||||
parameterize = lambda do |name, value|
|
||||
if name == :controller
|
||||
value
|
||||
elsif value.is_a?(Array)
|
||||
value.map { |v| Rack::Mount::Utils.escape_uri(v.to_param) }.join('/')
|
||||
else
|
||||
return nil unless param = value.to_param
|
||||
param.split('/').map { |v| Rack::Mount::Utils.escape_uri(v) }.join("/")
|
||||
end
|
||||
end
|
||||
{:parameterize => parameterize}
|
||||
end
|
||||
|
||||
def raise_routing_error
|
||||
raise ActionController::RoutingError.new("No route matches #{options.inspect}")
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue