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 4023888
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:39:13+00:00 2026-05-20T10:39:13+00:00

I’ve been trying to use a few different gems for displaying googlemaps within rails

  • 0

I’ve been trying to use a few different gems for displaying googlemaps within rails 3 and have had several problems.

Luckily I found this https://github.com/YouthTree/bhm-google-maps which is a helper and it seems to work for others.

I’ve installed it properly but in the readme https://github.com/YouthTree/bhm-google-maps/blob/master/README.md it mentions creating a class for the object to display in the view.

The example they gave was

class Location
   attr_accessor :address, :lat, :lng
   def initialize(address, lat, lng)
      @address = address
      @lat = lat
      @lng = lng
   end
  def to_s; address.to_s; end
end

And then running

 <%= draw_map_of Location.new("My House", 12.345, 56.789) %>

in the view.

It seems simple enough but I haven’t experienced the need of creating a class before in rails so I have some questions.

Should I create a location.rb file and place the above code in it, but where should I place the file? (model folder, application folder????)

Is there a way for me to create this class within my controller?

Ideally I would like to manipulate the lat/lng values as variables and display a dynamic map.

  • 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-05-20T10:39:14+00:00Added an answer on May 20, 2026 at 10:39 am

    You should put location.rb wherever you feel it makes the most sense. Having it at app/models/location.rb will ensure that it’s automatically required when your app starts, but some people expect that classes in app/models are backed by ActiveRecord.

    You could also put it under lib/ if you prefer.

    To make it available to the app, you can include require statement in project initializers inside your config folder:

    require "#{Rails.root}/lib/location.rb"
    

    As for creating it inside your Controller – definitely! It’s just another instance of a class:

    def show
      @location = Location.new("My House", 12.345, 56.789)
    end
    

    And then in your view:

    <%= draw_map_of @location %>
    

    Don’t forget – beneath Rails is all the power and flexibility of pure Ruby, ready to be used. You’re not only limited to what Rails gives you.

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I am trying to loop through a bunch of documents I have to put
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,

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.