svenfuchs / routing-filter

routing-filter wraps around the complex beast that the Rails routing system is, allowing for unseen flexibility and power in Rails URL recognition and generation.
http://www.artweb-design.de
MIT License
464 stars 84 forks source link

uninitialized constant RoutingFilter::Filter #27

Closed ghost closed 12 years ago

ghost commented 13 years ago

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
mjonuschat commented 12 years ago

Did you try adding

require 'routing_filter'

or maybe just

require 'routing_filter/filter'

before defining your Country filter?

mykola-kyryk commented 12 years ago

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

mjonuschat commented 12 years ago

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.

mjonuschat commented 12 years ago

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.