Class | ActionController::Routing::RouteSet::NamedRouteCollection
In: | lib/route_set_override.rb
Parent: | Object

### Methods

define_url_helper

### Public Instance methods

define_url_helper(route, name, kind, options)

[Source]

        # File lib/route_set_override.rb, line 5
     5:         def define_url_helper(route, name, kind, options)
     6:           selector = url_helper_name(name, kind)
     7:           # The segment keys used for positional paramters
     8:
     9:           hash_access_method = hash_access_name(name, kind)
    10:
    11:           # allow ordered parameters to be associated with corresponding
    12:           # dynamic segments, so you can do
    13:           #
    14:           #   foo_url(bar, baz, bang)
    15:           #
    16:           # instead of
    17:           #
    18:           #   foo_url(:bar => bar, :baz => baz, :bang => bang)
    19:           #
    20:           # Also allow options hash, so you can do
    21:           #
    22:           #   foo_url(bar, baz, bang, :sort_by => 'baz')
    23:           #
    24:           @module.module_eval "def \#{selector}(*args)\n\n\#{generate_optimisation_block(route, kind)}\nlocale = \#{route.segment_keys.include?(:locale) ? '{ :locale => I18n.locale || I18n.default_locale }' : '{}'}\n\nopts = if args.empty? || Hash === args.first\nargs.first || {}\nelse\noptions = args.extract_options!\n# args = args.zip(\#{route.segment_keys.inspect}).inject({}) do |h, (v, k)|\n\nsegments = \#{route.segment_keys.inspect}\n\#{'segments.delete(:locale) if segments.size > args.size' if route.segment_keys.include?(:locale)}\n\nargs = args.zip(segments).inject({}) do |h, (v, k)|\nh[k] = v\nh\nend\noptions.merge(args)\nend\n\n# url_for(\#{hash_access_method}(opts))\nurl_for(\#{hash_access_method}(locale.merge(opts)))\nend\nprotected :\#{selector}\n" # We use module_eval to avoid leaks
    25:           helpers << selector
    26:         end

[Validate]