I'm not exactly sure if this is a bug or not, but it did confuse me for a while. I'm using the gmaps4rails gem version 1.5.2 with Mongoid. In my controller, I've been doing this:
@places = Place.all.desc(:longitude)
@json = @places.to_gmaps4rails do |place, marker|
The JSON generated by this doesn't contain the id field. It turns out you need to use @places.to_a.to_gmaps4rails.... for the id to appear in JSON. This is the code that worked for me:
@json = @places.to_a.to_gmaps4rails do |place, marker|
I haven't tried this with ActiveRecord, so I'm not sure if this is the expected behavior there, but most of the examples I see don't seem to have to_a called on it. Could you confirm if this is the expected behavior?
Sure, I'll try adding this tomorrow and send in a pull request.
@apneadiving I got it to work by adding the method to Mongoid::Criteria. However, couldn't we avoid the duplication by adding the method to Enumerable module rather than the Array class? After all, Enumerable is included in Array as well as Mongoid::Criteria.
I ran the tests after moving to_gmaps4rails to Enumerable, and all the tests are running fine. This also works fine with Mongoid.
Ok, I'll make the changes and send in a pull request later today.
Add to_gmaps4rails method to Enumerable rather than Array. Fixes issue …
- Rename lib/gmaps4rails/extensions/array.rb to lib/gmaps4rails/extensions/enumerable.rb.
- Add redcar temp files to .gitignore.