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

undefined method `to_gmaps4rails' #139

Closed HungYuHei closed 12 years ago

HungYuHei commented 12 years ago

I've done everything that the README said

but I still got "undefined method `to_gmaps4rails' for #User:0x007f9ea726af78" error

btw, my environment is : rails3.1, mongoid2.3.3, gmaps4rails1.4.2

and here is my Model snippet:

class User
  include Mongoid::Document

  acts_as_gmappable
  field :name
end

my controller:

...
@json = @user.to_gmaps4rails
...

Did I miss something ?

HungYuHei commented 12 years ago

a moment ago, I changed something(but I forgot the details), then I got "undefined method `gmaps4rails_options'"

please notice that the piror error I mentioned is "undefined method `to_gmaps4rails'" which is different

PikachuEXE commented 12 years ago

I have made a pull request for this If you are just developing you can use my repo branch is "MoveIn.."

apneadiving commented 12 years ago

just released 1.4.3 let me know if you still have this problem

HungYuHei commented 12 years ago

Due to this issue, right now I manually call the google-map API instead of using the gem

However, I would like to do some test later :)

zolzaya commented 12 years ago

I have a same issue over here. My environment is :

  1. Rails 3.2.1
  2. Mongoid 2.4.3
  3. gmaps4rails 1.4.5
apneadiving commented 12 years ago

@zolzaya : ok I think I understand.

In Mongoid: User.all is a Mongoid::Criteria. I should add to_gmaps4rails to this class.

In the meantime, you can simply do: User.all.to_a.to_gmaps4rails

zolzaya commented 12 years ago

Thank you for reply. It's working fine. :)

ornerymoose commented 12 years ago

Apnea, I have encountered this problem many a time: undefined method gmaps4rails_options. The only way I can bypass it is by doing .to_json instead. However, that is in the case of polylines, polygons, etc etc. But when it comes to markers, even if I do .to_json, I just get a grey map :(

This is incredibly frustrating. Any ideas?

Rails 3.2.3 ruby 1.9.3p0

Edit: I just did bundle update and now it's gmaps4rails 1.4.8 (still same error). Certain version I should try? I'll try 1.4.3.

apneadiving commented 12 years ago

@DavidPardy : what orm do you use?

ornerymoose commented 12 years ago

I'm new to web dev but I'm fairly certain the ORM would be Active Record?

Also here's a github to what I'm trying to accomplish. Fairly simple: create a location in /locations, create a map in /maps using the location_id, and boom the location shows up on the map as a placemark.

https://github.com/DavidPardy/Placemarks-Using-Gmaps4Rails

Edit: The map controller and map view is a little messy, just because I'm toying with stuff. Also, I have tried 1.4.3, 1.4.7, and 1.4.8, not working for any.

apneadiving commented 12 years ago

Well you do Map.all.to_gmaps4rails but Map doesn't contain acts_as_gmappable

ornerymoose commented 12 years ago

Right, good call, not sure how I missed that. n00b like I said.

I amaze myself sometimes. I just started a new app with just a map model and that's much easier.

Thanks alot for your help sir, greatly appreciate it.

apneadiving commented 12 years ago

@DavidPardy No problem, we all face this kind of situation. Have fun coding :)

ornerymoose commented 12 years ago

Don't hate me if I come back with more questions later, lol :)

apneadiving commented 12 years ago

@DavidPardy Issue tracker is made for issues, please ask questions on stackoverflow.

rajesh2210 commented 10 years ago

I am using gmaps4rails gem to show map on view part. gmaps4rails '1.5.6' rails 4.0.0 ruby 2.0.0

Model Action class Location < ActiveRecord::Base acts_as_gmappable

def gmaps4rails_address location end end

Controller Action class LocationsController < ApplicationController def show binding.pry @locations = Location.all.to_gmaps4rails end end

Here its showing **NoMethodError: undefined method `to_gmap4rails' # Any response please reply

apneadiving commented 10 years ago

1.5.6 is not compatible with rails 4

rajesh2210 commented 10 years ago

But i have created one dummy app with rails 4 its working fine.

apneadiving commented 10 years ago

to_gmap4rails should be to_gmaps4rails...............

rajesh2210 commented 10 years ago

yes i did silly mistake sorry for disturbing.

Thanks alot

its working fine.

apneadiving commented 10 years ago

By the way, stop spamming the issues, post questions on stackoverflow

rajesh2210 commented 10 years ago

ok thanks