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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:31:04+00:00 2026-06-14T04:31:04+00:00

I am trying to insert latitude and longitude values from a database into my

  • 0

I am trying to insert latitude and longitude values from a database into my google maps coffeescript.

jQuery ->
  initialize()

initialize = ->
  myOptions =
    center: new google.maps.LatLng(<%= @location.latitude %>, <%= @location.longitude %>)
    zoom: 12
    mapTypeControlOptions: {mapTypeIds: ["OSM", "OCM", "MQ", google.maps.MapTypeId.HYBRID]}
  map = new google.maps.Map $('#map_canvas')[0], myOptions

[…]

I get the following error message:

 undefined method `latitude' for nil:NilClass
   (in /Users/sg/rails-projects/geo_rails_test/app/assets/javascripts/gmap.js.coffee.erb)

suggesting that my Location Object

@location = Location.find(params[:id])

has not yet been instantiated at the time of parsing the js.coffee.erb file. (??)

I have tested the coffeescript with hard-coded values and @location.latitude works perfectly in my view.
Any ideas what’s going wrong?

  • 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-14T04:31:06+00:00Added an answer on June 14, 2026 at 4:31 am

    Your (Java|Coffee)Script assets will be processed and sent to the browser before your controller even runs. That means that @location won’t come from your controller, it will come from whatever self happens to be when your .js.coffee.erb is converted to JavaScript. When deploying to production, the assets will (or at least should be) compiled before anything even hits your production system so @location has no hope of being anything useful.

    You should build your data in your controller’s ERB rather than the asset:

    <!-- Somewhere in the appropriate app/views/... file... -->
    <script type="text/javascript">
        window.global_location = { lat: <%= @location.latitude %>, lng: <%= @location.longitude %> }; 
    </script>
    

    and then your asset can get the data through the this_location global:

    center: new google.maps.LatLng(global_loc.lat, global_loc.lng)
    

    Or you could try loading the location through an AJAX call.

    Only use ERB in your assets for per-application constants and configuration values, don’t try to use ERB in your assets for anything that will change while your application is running.

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

Sidebar

Related Questions

Trying to insert values with Unicode Chars into a MySQL-database using Delphi 2010 and
Im trying to insert something in persian into my Database (SQL server 2008) from
Trying to insert into a mongodb database from scala. the below codes dont create
Trying to insert 315K Gif files into an Oracle 10g database. Everytime I get
im trying to insert this query with mysql_query INSERT INTO um_group_rights (`um_group_id`,`cms_usecase_id`,`um_right_id`) VALUES (2,1,1)
Trying to insert a large audio file into an Oracle 10g database and keep
I have saved bounds in my database table coming from google maps. Now i
hi i am trying to get latitude and longitude values by address function get_lat_long_from_address($address)
In the below code, I am trying insert the records from excel to Database
Im trying to insert values into a table where the ID of the row

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.