apneadiving / Google-Maps-for-Rails

Enables easy Google map + overlays creation in Ruby apps
https://apneadiving.github.io/
MIT License
2.26k stars 382 forks source link

wrong number of arguments exception #307

Closed stestaub closed 10 years ago

stestaub commented 11 years ago

I wanted to use gmaps4rails in my application but i can't get it to work. It works as long as I simply use the view helper gmaps with only the map options. But as soon as I add poliylines or markers I get a "wrong number of arguments (0 for 1)" exception.

Here is the top part of the stacktrace:

sinatra (1.3.3) lib/sinatra/base.rb:1231:in `options'
sinatra (1.3.3) lib/sinatra/base.rb:1660:in `block (2 levels) in delegate'
/home/stefan/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/bundler/gems/Google-Maps-for-Rails-b76ec946fe20/lib/gmaps4rails/js_builder.rb:94:in `options'
/home/stefan/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/bundler/gems/Google-Maps-for-Rails-b76ec946fe20/lib/gmaps4rails/js_builder.rb:124:in `set_configuration_variables'
/home/stefan/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/bundler/gems/Google-Maps-for-Rails-b76ec946fe20/lib/gmaps4rails/js_builder.rb:110:in `create_standard_js'
/home/stefan/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/bundler/gems/Google-Maps-for-Rails-b76ec946fe20/lib/gmaps4rails/js_builder.rb:105:in `create_js'
/home/stefan/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/bundler/gems/Google-Maps-for-Rails-b76ec946fe20/lib/gmaps4rails/js_builder.rb:57:in `block in process_data'
/home/stefan/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/bundler/gems/Google-Maps-for-Rails-b76ec946fe20/lib/gmaps4rails/js_builder.rb:55:in `each'
/home/stefan/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/bundler/gems/Google-Maps-for-Rails-b76ec946fe20/lib/gmaps4rails/js_builder.rb:55:in `process_data'
/home/stefan/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/bundler/gems/Google-Maps-for-Rails-b76ec946fe20/lib/gmaps4rails/js_builder.rb:31:in `create_js'
/home/stefan/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/bundler/gems/Google-Maps-for-Rails-b76ec946fe20/lib/gmaps4rails/base.rb:47:in `create_js_from_hash'
/home/stefan/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/bundler/gems/Google-Maps-for-Rails-b76ec946fe20/lib/gmaps4rails/extensions/hash.rb:6:in `to_gmaps4rails'
/home/stefan/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/bundler/gems/Google-Maps-for-Rails-b76ec946fe20/app/views/gmaps4rails/_gmaps4rails.html.erb:5:in `block in 

I tried it with the samples from the wiki. Here is my code I used:

<%= gmaps({
    "map_options" => { "type" => "SATELLITE", "center_latitude" => 0, "center_longitude" => 180, "zoom" => 3, "auto_adjust" => true},
    "markers"     => { "data" => '[{ "description": "", "title": "", "lng": "5.9311119", "lat": "43.1251606", "picture": "", "width": "", "height": "" },
    {"description": "", "title": "", "lng": "2.3509871", "lat": "48.8566667", "picture": "", "width": "", "height": "" } ]'}}) %>

Here some additional Information about my environment:

Thanks for any suggestions

apneadiving commented 11 years ago

Do you redefine delegate here: lib/sinatra/base.rb:1231 ?

apneadiving commented 11 years ago

this should confirm the bug, please confirm: https://github.com/apneadiving/Google-Maps-for-Rails/commit/3ff52deb455e1077c9f60660486fcd38f78e737f

stestaub commented 11 years ago

Hello apneadiving. I didn't redifine delegate as far as I know. Perhaps some of the libraries I use do. I will try your fix today. Thank you for that. Next week I will try to find out what library caused the problem.

apneadiving commented 11 years ago

Actually, your log speak from themselves: it's sinatra. It's included when you use things like DelayedJob for instance.

Did you try my fix?

On Jan 2, 2013, at 3:58 PM, Stefan Staub notifications@github.com wrote:

Hello apneadiving. I didn't redifine delegate as far as I know. Perhaps some of the libraries I use do. I will try your fix today. Thank you for that. Next week I will try to find out what library caused the problem.

— Reply to this email directly or view it on GitHub.

stestaub commented 11 years ago

Yes I tried it, but I get the same error. But the strange thing for me is, that when I define some delegates by my own in the controller class they work...

Edit: I think I know why, maybe sinatra would not be called in my situation i tried...

stestaub commented 11 years ago

I will set up a new clean project with only gmaps4rails and then add some of my other libraries like as you said delayed_job

apneadiving commented 11 years ago

Damn, you tried with the latest master on github?

stestaub commented 11 years ago

Yes I used the version you provided: here the stacktrace:

sinatra (1.3.3) lib/sinatra/base.rb:1231:in `options'
sinatra (1.3.3) lib/sinatra/base.rb:1660:in `block (2 levels) in delegate'
/home/stefan/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/bundler/gems/Google-Maps-for-Rails-3ff52deb455e/lib/gmaps4rails/js_builder.rb:124:in `set_configuration_variables'
apneadiving commented 11 years ago

But I don't use delegate anymore... thanks for digging into this :)

stestaub commented 11 years ago

ok I now found out what gem is causing this issue. It's delayed_job_web... To reproduce simply create a project and add delayed_job and delayed_job_web to the gemfile.

For now I can remove delayed_job_web from my project.

Thank you for your help and for the hint to delayed_job :)

apneadiving commented 11 years ago

Thanks for reporting. I'll try to understand why it messes with Rails...

On Jan 2, 2013, at 4:47 PM, Stefan Staub notifications@github.com wrote:

ok I now found out what gem is causing this issue. It's delayed_job_web... To reproduce simply create a project and add delayed_job and delayed_job_web to the gemfile.

For now I can remove delayed_job_web from my project.

Thank you for your help and for the hint to delayed_job :)

— Reply to this email directly or view it on GitHub.

yagudaev commented 11 years ago

I also ran into this issue today using version (1.5.6) after upgrading from (1.5.2) which works great.

So until this is resolved the workaround is simply to use the older version.

In your Gemfile

gem 'gmaps4rails', '1.5.2'
cutalion commented 11 years ago

I've got the same error after I have added sinatra to my rails project (dependency of sidekiq dashboard).

ArgumentError: wrong number of arguments (0 for 1)
from /home/cutalion/.rvm/gems/ruby-1.9.3-p385@groceryhelper/gems/sinatra-1.3.6/lib/sinatra/base.rb:1259:in `options'
ActionView::Template::Error (wrong number of arguments (0 for 1)):
    2: <%= javascript_include_tag *js_dependencies %>
    3: 
    4: <script type="text/javascript">
    5: <%=raw options.to_gmaps4rails %>
    6: </script>
    7: <% end %>
    8: 
cutalion commented 11 years ago

Quick and dirty solution - add empty options to markers, polygons, circles, etc

= gmaps markers: { data: draw_stores(stores), options: {} },
        circles: { data: [{ lng: area[:longitude], lat: area[:latitude], radius: area[:radius] }].to_json, options: {} }}
rkh commented 11 years ago

This can be solved by either implementing respond_to? properly on your object (I assume you're using method_missing) or by upgrading to Sinatra 1.4.