Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7943775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:22:16+00:00 2026-06-04T00:22:16+00:00

I have a map which has got marker based on state of US. Each

  • 0

I have a map which has got marker based on state of US. Each state has n number of city.

I have got a state model, controller and city model, controller.

When I click on the marker of the state, I want the list of cities to be displayed in the info window.

All this information is appearing on the homepage.

This is what I have done so far :-

home_controller.rb

def index
    @states = State.all.to_gmaps4rails do |state,marker|
        marker.infowindow render_to_string(:partial => "/states/gmaps4rails_infowindow", :locals => {:object => state})
        marker.json({:id => state.id})
    end
end

home/index.html.haml

=gmaps({"map_options" =>{ "auto_zoom" => false, "zoom" => 3}, "markers" => { "data" => @states } })

state_controller.rb

def gmaps4rails_infowindow
  @state = Gmaps.map.markers
end

states/_gmaps4rails_infowindow.html.haml

=@state.cities.each do |city|
    =city.name

Needless to say that it is not working. Can someone please help me out?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T00:22:17+00:00Added an answer on June 4, 2026 at 12:22 am

    Well, your home_controller.rb is fine. you write here you want to use a partial with a local variable named object.

    In the partial itself, you write:

    =@state.cities.each do |city|
      =city.name
    

    The instance variable isn’t defined there, you defined a local variable just above.

    Replace with:

    =object.cities.each do |city|
      =city.name
    

    From there it should work.


    Notice:

    def gmaps4rails_infowindow
      @state = Gmaps.map.markers 
    end
    

    is:

    • useless: you define the infowindow in the controller

    • wrong: Gmaps.map.markers only lives as js variable

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Map model, which defines the details for an ASCII-art map for
I have created a map (experimental) which has a '#' value if there is
I've got a value type that I want put into a map. It has
I have a map which has only one input field where the user will
I already have an Hash map of school which has key as student's first
I have a Google V3 map which uses steetView and some map markers. The
I have made a map with jQuery which is split up in many regions,
Is it preferred to have one depot with multiple folders which map to different
I have a bean which I map to the database using Hibernate. I'm using
I have an unordered map: class O(val a: Int) Map[String, List[O]] which I'd like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.