Sha256: 360e1186914a9929a723968f0573e090770f76339dae8cbe25c5af2b2ab4237b

Contents?: true

Size: 814 Bytes

Versions: 8

Compression:

Stored size: 814 Bytes

Contents

# make route_set generator pass the current segment/param name to to_param
# if arity allows it. so we can use param names in routes and distinguish them
# in the model.

require 'action_dispatch/routing/route_set'

ActionDispatch::Routing::RouteSet::Generator.class_eval do
  def opts
    parameterize = lambda do |name, value|
      if name == :controller
        value
      elsif value.is_a?(Array)
        value.map { |v| Rack::Mount::Utils.escape_uri(to_param(name, v)) }.join('/')
      else
        return nil unless param = to_param(name, value)
        param.split('/').map { |v| Rack::Mount::Utils.escape_uri(v) }.join("/")
      end
    end
    {:parameterize => parameterize}
  end
  
  def to_param(name, value)
    value.method(:to_param).arity == 1 ? value.to_param(name) : value.to_param
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
adva-core-0.0.9 lib/patches/rails/route_set_to_param.rb
adva-core-0.0.8 lib/patches/rails/route_set_to_param.rb
adva-core-0.0.7 lib/patches/rails/route_set_to_param.rb
adva-core-0.0.6 lib/patches/rails/route_set_to_param.rb
adva-core-0.0.5 lib/patches/rails/route_set_to_param.rb
adva-core-0.0.4 lib/patches/rails/route_set_to_param.rb
adva-core-0.0.2 lib/patches/rails/route_set_to_param.rb
adva-core-0.0.1 lib/patches/rails/route_set_to_param.rb