I wondered why routing does not pass the current route segment key to
to_param if to_param accepts a parameter.
This would allow to have a route like
and then pass the named url generation helper an article like so:
# => "articles/the-permalink"
when the Article class defines to_param like so:
respond_to?(key) ? send(key).to_s : super()
or something similar ...
This would make to_param somewhat more context sensitive in that the
user can define to some extend in the route what kind of param the
route expects to get from the model. It also makes it easier to define
higher level url helpers without baking too much knowledge about the
routes into them.
This could be done by testing method(:to_param).arity in routing so it
does not change any behaviour except when the user explicitely defines
to_param with a parameter. Something like:
# to be used in 4 places in routing that call to_param
def self.to_param(object, key)
object.method(:to_param).arity == 0 ? object.to_param :
I'd look into a patch but thought it makes sense to ask here first.