svenfuchs/routing-filter

uninitialized constant RoutingFilter::Filter

Closed this issue · 4 comments

When I use bundler with the latest code on rails 2.3.11 it gives me the following error.

Here is my sample filter /lib/routing_filter.rb:

module RoutingFilter
  class Country < Filter
    # remove the locale from the beginning of the path, pass the path
    # to the given block and set it to the resulting params hash
    def around_recognize(path, env, &block)
      country = nil
      path.sub! %r(^/(italy|france|spain)(?=/|$)) do country = $1; '' end
      returning yield do |params|
        params[:country] = country || 'italy'
      end
    end

    def around_generate(*args, &block)
      country = args.extract_options!.delete(:country) || 'italy'
      returning yield do |result|
        if country != 'italy'
          result.sub!(%r(^(http.?://[^/]*)?(.*))){ "#{$1}/#{country}#{$2}" }
        end 
      end
    end

  end
end

And my /config/routes.rb:

ActionController::Routing::Routes.draw do |main|
  filter :country
end

Did you try adding

require 'routing_filter'

or maybe just

require 'routing_filter/filter'

before defining your Country filter?

Requiring 'routing_filter' doesn't resolve the issue for me. Any ideas?

I'm pretty sure it has something to do with your app or the load paths. I just created a new rails 2.3.14 app, took the country filter from a few comments above, stuck it into lib/routing_filter/country.rb and could use it in the routes file without any error.

Works on 3.1.4 and 3.2.3 as well, closing this as it's not reproducible. Please re-open if there is a documented way to show this error.