svenfuchs / adva_cms

cutting edge cms, blog, wiki, forum ...
http://adva-cms.org
MIT License
491 stars 74 forks source link

"wrong number of arguments (2 for 0)" error when running on Ruby 1.9 #8

Open TylerRick opened 14 years ago

TylerRick commented 14 years ago

When I go to http://localhost:3002/, I get this error:

wrong number of arguments (2 for 0)

vendor/plugins/adva_cms/vendor/plugins/routing-filter/lib/routing_filter/pagination.rb:7:in `around_recognize'
vendor/plugins/adva_cms/vendor/plugins/routing-filter/lib/routing_filter/base.rb:15:in `run'
vendor/plugins/adva_cms/vendor/plugins/routing-filter/lib/routing_filter.rb:12:in `run'
vendor/plugins/adva_cms/vendor/plugins/routing-filter/lib/routing_filter.rb:57:in `recognize_path_with_filtering'
/var/lib/gems/1.9.1/gems/actionpack-2.3.5/lib/action_controller/routing/route_set.rb:441:in `recognize'
/var/lib/gems/1.9.1/gems/actionpack-2.3.5/lib/action_controller/routing/route_set.rb:436:in `call'

I don't get that error when I change script/server to use ruby1.8:

-#!/usr/bin/env ruby
+#!/usr/bin/env ruby1.8

(But that is not an option for me.)

TylerRick commented 14 years ago

It looks like the problem is that the lambda in vendor/plugins/routing-filter/lib/routing_filter/base.rb is not defined with any parameters but it is called with 2.

Unlike Ruby 1.8, 1.9 actually enforces the arity of procs created with lambda:

RUBY_VERSION = 1.9.1
 > proc = lambda {}; proc.call(1,2)
ArgumentError: wrong number of arguments (2 for 0)
    from (irb):2:in `call'

RUBY_VERSION = 1.8.7
 > proc = lambda {}; proc.call(1,2)
=> nil

Changing it to a proc fixed it for me:

diff --git a/engines/adva_cms/vendor/plugins/routing-filter/lib/routing_filter/base.rb b/engines/adva_cms/vendor/plugins/routing-filter/lib/routing_filter/base.rb
index 73964ad..c8d2c80 100644
--- a/engines/adva_cms/vendor/plugins/routing-filter/lib/routing_filter/base.rb
+++ b/engines/adva_cms/vendor/plugins/routing-filter/lib/routing_filter/base.rb
@@ -11,8 +11,8 @@ module RoutingFilter
     end

     def run(method, *args, &block)
-      successor = @successor ? lambda { @successor.run(method, *args, &block) } : block
+      successor = @successor ? proc {|path, env| @successor.run(method, *args, &block) } : block
       active ? send(method, *args, &successor) : successor.call(*args)
     end
   end
-end
\ No newline at end of file
+end

(procs created with Kernel#proc aren't subject to the arity check that those created with Kernel#lambda are. And if we simply add the 2 parameters, I got this opposite error instead: wrong number of arguments (0 for 2))

TylerRick commented 14 years ago

I've fixed this and to other Ruby 1.9 issues in my fork. Please pull from git://github.com/TylerRick/adva_cms.git