Created
February 21, 2011 03:35
-
-
Save elucid/836628 to your computer and use it in GitHub Desktop.
port Merb's :identify routing option to Rails 3 router
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# see actionpack/lib/action_dispatch/routing/route_set.rb | |
module ActionDispatch | |
module Routing | |
class RouteSet | |
class Generator | |
# modified to allow :identify option ala Merb routing | |
def opts # :nodoc: | |
parameterize = lambda do |name, value| | |
to_param = lambda do |val| | |
if options[:identify] and name == :id and not val.is_a?(String) | |
val.send options[:identify] | |
else | |
val.to_param | |
end | |
end | |
if name == :controller | |
value | |
elsif value.is_a?(Array) | |
value.map { |v| Rack::Mount::Utils.escape_uri(to_param[v]) }.join('/') | |
else | |
return nil unless param = to_param[value] | |
param.split('/').map { |v| Rack::Mount::Utils.escape_uri(v) }.join("/") | |
end | |
end | |
{:parameterize => parameterize} | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment