Greetings all,

I've just started learning Ruby (and Geo Ruby), and am trying to create overlays for Google Maps.

I found a [seemingly] great tutorial for doing this HERE

...and it uses Ruby to generate the final javascript - cool, eh?

Have everything installed properly (as far as I can tell - gem list gives me the whole bundle including: mysql (2.8.1)).
MySQL working fine.

I get this error when trying to run the script (attached) from a shell:

Command:

$ ruby ./Desktop/gen_encpolygons.rb

Returns:

./Desktop/gen_encpolygons.rb:11:in `initialize': wrong number of
arguments (4 for 0) (ArgumentError)
  from ./Desktop/gen_encpolygons.rb:11:in `new'
  from ./Desktop/gen_encpolygons.rb:11:in `generate_js_border_overlay'
  from ./Desktop/gen_encpolygons.rb:95

I've googled extensively for similar argument errors, and I'm not finding any good matches (or solutions).

...so I opened an irb session to try a little test:

Command:

Mysql::new('localhost', 'root', '', 'my_database')

Returns:

NameError: uninitialized constant Mysql
  from (irb):1

Then I checked for the gem:
>> require 'mysql'
=> true

Any help is greatly appreciated.

System info:
MacBook Pro
OS X 10.5.8
2.6 GHz Intel Core 2 Duo
MAMP v. 1.9.4

Best,
Micah

Recommended Answers

All 14 Replies

The error tells you that the call in line 11 is wrong. In the code, it attempts to pass in 4 arguments, but the actual function requires no argument. You need to check on that line. Also, it seems that the line is calling line 95 in the code. I am guessing that line 95 is the function prototype (def ....) which should tell you exactly how the function should be called.

Hi Taywin,

Thanks for replying.

Line 11 is:

borderDB = Mysql::new('localhost', 'root', '', 'my_database')

Line 95 is:

generate_js_border_overlay("/tmp/bordersOverlay.js")

...but as you'll see in the code (attached to first post) the problem could be somewhere between lines 11 and 55.

I'm just not able to spot the bug, or determine if it is a problem with the code, or something else.

Thanks again.

Micah

OK... Just downloaded the code and look at it. The error in line 95 occurs because it call the function generate_js_border_overlay. Then, the problem is actually from line 11 where it attempts to create mysql using mysql module. Do you have module mysql installed? The one under ruby library folder.

When ruby creates a definition, it also expect the same number of argument passing to the function. If it mismatches the number, ArgumentError exception will be thrown.

Using irb won't help in this case because you need 3 modules - rubygems, mysql, and geo_ruby. If you have them, try to type require 'mysql' in the irb to see if you have the gem installed correctly. By the way, do you have all those gems? Try 'gem -v' to see if you have ruby gem installed. Then try 'gem list --local' to see what you have. In your gem, you must have both mysql and geo_ruby gems.

That's all I can think of right now...

Hi Taywin,

Thank you for the post.

>> require 'geo_ruby'
=> true
>> require 'mysql'
=> true

I have gems installed.
mysql (2.8.1)
GeoRuby (1.3.4)
...among all the others.

MWmbPro:~ Wolfemac$ gem -v
1.3.6

I believe I have everything installed correctly, and everything should be set up to run correctly through MAMP.

Is there anyway I can check to make sure something isn't messed up on the install? I can't see any problems with the code, so I assume it must be something wrong with my ruby install - although that all seems to be working properly as well.

Thanks again for the help.

Best,
Micah

Hmm... I don't have the access to the code I have coded in Ruby that use another type of database connection class... Then you could hack the code and change it to another database connection class of your choice... Are you in hurry of this? I may not be able to get back until Monday for the code...

Hi Taywin,

Thanks again for all the help, this really has me stumped. Monday is fine, I'm just grateful for the help.

Best,
Micah

OK, I would want you try this...

# change the line 11
borderDB = Mysql::new('localhost', 'root', '', 'my_database')

# to
borderDB = Mysql.real_connect('localhost', 'root', '', 'my_database')

By the way, the script use 'root' user to access without password. If you have a password for 'root', you must give the password there.

Hi Taywin,

Thank you again for your patience and assistance on this.

Now I get this error:

./Desktop/gen_encpolygons.rb:11:in `generate_js_border_overlay': undefined method `real_connect' for Mysql:Class (NoMethodError)
	from ./Desktop/gen_encpolygons.rb:95

I also re-checked my gem:

$ gem list --local | grep mysql
mysql (2.8.1)

Do you think I need to uninstall the gem mysql and install gem ruby-mysql? Would the "pure ruby" gem fix this?

Still lost...but at least it's a different error, that's progress, right? ;-)

Thanks,
Micah

Hmm... Do you have the MySQL server installed? You still need the real MySQL in your computer. Only gems won't actually work. Here is the API of the MySQL your script may need. I used it to do the work for storing certain stuff I search from the Internet to the database for me. I remember that using MySQL::new created certain problem and people would not use it anymore. The script you gave looks out-dated too. :(

Hi Taywin,

MySQL: Client API version 5.1.44

Thanks again, I'm going to try this -- and possibly a reinstall as well.

I'll let you know how it goes.

Thank you very much for all the help, I really appreciate it.

Best,
Micah

I hope you get it to work. I just checked my Linux box and it doesn't have mysql gem in it; however, I can still use 'require mysql'. Yet, you may not need to uninstall the gem but rather install the MySQL to your computer. :)

Hi Taywin,

I'm using MAMP, do you think that might have something to do with it? I can always reinstall MySQL if that's the problem.

Thanks again for the help. I'll let you know how it goes.

Best,
Micah

If the installation includes the MySQL libraries that ruby is looking for, it should be able to find it. I am guessing that the way MAMP installs the MySQL is not the way ruby can see the library. You may try to reinstall MySQL and see how it work? :)

you could hack the code and change it to another database connection class of your choice... Are you in hurry of this? I may not be able to get back until Monday for the code...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.