开发者

Error when monkey patching ActionDispatch::Routing in Rails 3.1 with autoload_path

Similar to the Gem tasteful-routes (https://github.com/icelab/tasteful-routes/blob/master/lib/tasteful_routes/mapper.rb) I wanted to be able to add some methods as routing helpers.

I have a file lib/action_dispatch/routing/mapper.rb which contains

puts "In mapper.rb"
module ActionDispatch::Routing
  class Mapper
    module NorthStar
      def star(controller)
        puts "Testing!"
      end
    end
    include NorthStar
  end
end

To autoload this I placed the following in config/application.rb

config.autoload_paths += Dir["#{config.root}/lib/**/"]

When I try to run Rails, I run into an issue.

20 ~/Dropbox/Development/RailsPlayground/site$ rails s
=> Booting WEBrick
=> Rails 3.1.0.rc3 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
In mapper.rb
Exiting
/Users/basicxman/.rvm/gems/ruby-1.9.2-p136/gems/actionpack-3.1.0.rc3/lib/sprockets/railtie.rb:40:in `block (2 levels) in <class:Railtie>': undefined method `mount' for #<ActionDispatch::Routing::Mapper:0x00000100933b30> (NoMethodError)
  from /Users/basicxman/.rvm/gems/ruby-1.9.2-p136/gems/actionpack-3.1.0.rc3/lib/action_dispatch/routing/route_set.rb:257:in `instance_exec'
  from /Users/basicxman/.rvm/gems/ruby-1.9.2-p136/gems/actionpack-3.1.0.rc3/lib/action_dispatch/routing/route_set.rb:257:in `eval_block'
  from /Users/basicxman/.rvm/gems/ruby-1.9.2-p136/gems/actionpack-3.1.0.rc3/lib/action_dispatch/routing/route_set.rb:276:in `block in clear!'
  from /Users/basicxman/.rvm/gems/ruby-1.9.2-p136/gems/actionpack-3.1.0.rc3/lib/action_dispatch/routing/route_set.rb:276:in `each'
  from /Users/basicxman/.rvm/gems/ruby-1.9.2-p136/gems/actionpack-3.1.0.rc3/lib/action_dispatch/routing/route_set.rb:276:in `clear!'
  from /Users/basicxman/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.1.0.rc3/lib/rails/application/routes_reloader.rb:24:in `block in clear!'
  from /Users/basicxman/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.1.0.rc3/lib/rails/application/routes_reloader.rb:22:in `each'
  from /Users/basicxman/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.1.0.rc3/lib/rails/application/routes_reloader.rb:22:in `clear!'
  from /Users/basicxman/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.1.0.rc3/lib/rails/ap开发者_Python百科plication/routes_reloader.rb:12:in `reload!'
  from /Users/basicxman/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.1.0.rc3/lib/rails/application/routes_reloader.rb:7:in `block in initialize'
  from /Users/basicxman/.rvm/gems/ruby-1.9.2-p136/gems/activesupport-3.1.0.rc3/lib/active_support/file_update_checker.rb:32:in `call'
  from /Users/basicxman/.rvm/gems/ruby-1.9.2-p136/gems/activesupport-3.1.0.rc3/lib/active_support/file_update_checker.rb:32:in `execute_if_updated'
  from /Users/basicxman/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.1.0.rc3/lib/rails/application/finisher.rb:63:in `block (2 levels) in <module:Finisher>'
  from /Users/basicxman/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.1.0.rc3/lib/rails/application/finisher.rb:64:in `call'
  from /Users/basicxman/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.1.0.rc3/lib/rails/application/finisher.rb:64:in `block in <module:Finisher>'
  from /Users/basicxman/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.1.0.rc3/lib/rails/initializable.rb:25:in `instance_exec'
  from /Users/basicxman/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.1.0.rc3/lib/rails/initializable.rb:25:in `run'
  from /Users/basicxman/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.1.0.rc3/lib/rails/initializable.rb:50:in `block in run_initializers'
  from /Users/basicxman/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.1.0.rc3/lib/rails/initializable.rb:49:in `each'
  from /Users/basicxman/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.1.0.rc3/lib/rails/initializable.rb:49:in `run_initializers'
  from /Users/basicxman/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.1.0.rc3/lib/rails/application.rb:96:in `initialize!'
  from /Users/basicxman/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.1.0.rc3/lib/rails/railtie/configurable.rb:30:in `method_missing'
  from /Users/basicxman/Dropbox/Development/RailsPlayground/site/config/environment.rb:5:in `<top (required)>'
  from /Users/basicxman/Dropbox/Development/RailsPlayground/site/config.ru:4:in `require'
  from /Users/basicxman/Dropbox/Development/RailsPlayground/site/config.ru:4:in `block in <main>'
  from /Users/basicxman/.rvm/gems/ruby-1.9.2-p136/gems/rack-1.3.0/lib/rack/builder.rb:51:in `instance_eval'
  from /Users/basicxman/.rvm/gems/ruby-1.9.2-p136/gems/rack-1.3.0/lib/rack/builder.rb:51:in `initialize'
  from /Users/basicxman/Dropbox/Development/RailsPlayground/site/config.ru:1:in `new'
  from /Users/basicxman/Dropbox/Development/RailsPlayground/site/config.ru:1:in `<main>'
  from /Users/basicxman/.rvm/gems/ruby-1.9.2-p136/gems/rack-1.3.0/lib/rack/builder.rb:40:in `eval'
  from /Users/basicxman/.rvm/gems/ruby-1.9.2-p136/gems/rack-1.3.0/lib/rack/builder.rb:40:in `parse_file'
  from /Users/basicxman/.rvm/gems/ruby-1.9.2-p136/gems/rack-1.3.0/lib/rack/server.rb:200:in `app'
  from /Users/basicxman/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.1.0.rc3/lib/rails/commands/server.rb:46:in `app'
  from /Users/basicxman/.rvm/gems/ruby-1.9.2-p136/gems/rack-1.3.0/lib/rack/server.rb:301:in `wrapped_app'
  from /Users/basicxman/.rvm/gems/ruby-1.9.2-p136/gems/rack-1.3.0/lib/rack/server.rb:252:in `start'
  from /Users/basicxman/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.1.0.rc3/lib/rails/commands/server.rb:70:in `start'
  from /Users/basicxman/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.1.0.rc3/lib/rails/commands.rb:54:in `block in <top (required)>'
  from /Users/basicxman/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.1.0.rc3/lib/rails/commands.rb:49:in `tap'
  from /Users/basicxman/.rvm/gems/ruby-1.9.2-p136/gems/railties-3.1.0.rc3/lib/rails/commands.rb:49:in `<top (required)>'
  from script/rails:6:in `require'
  from script/rails:6:in `<main>'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜