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

  • Home
  • SEARCH
  • 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 5842993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:05:32+00:00 2026-05-22T12:05:32+00:00

Im curious what is the best way to pass my rails variables into javascript

  • 0

Im curious what is the best way to pass my rails variables into javascript code. For example i have this line in my controller:

@address = get_user_address
@farms = Farm.all

Now i need to use it for initialize my google map, for now im going with plain javascript and im more than sure that this is ugly solution. In view im have something like that

%script
  distance = []
  - @farms.each do |f|
    distance.push(['#{f.latitude}' + ',' + '#{f.longitude}' + ',' + '#{f.name}', #{f.distance_from(@address)}])
  distance.sort(sortMultiDimensional)
  user_coords = #{Geocoder.coordinates(@address)}

And google map initalize going under. How to avoid this ugly ruby-in-javascript code? Thanks!

  • 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-22T12:05:33+00:00Added an answer on May 22, 2026 at 12:05 pm

    Place the variables into the HTML of a rendered page then use javascript to read them from the DOM at execution time. This allows you to write the JS in separate files and without cluttering the file with random script variables.

    Be sure to sanitize user supplied variables.

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

Sidebar

Related Questions

I'm curious about what be the best way to model this for optimized performance...
First MVC project, just curious what the best way to manage this is. All
This is just a curious question. Which one is the best way to update
I am curious about what is the best way to do this: assume I
I am curious which is the best way to convert time like this 2008-04-23
Being somewhat typographically obsessed, I am curious: what is the best way to present
I know this is a subjective question, but I'm always curious about best-practices in
Just curious what is the best practice for solving the following issue. I have
hey all, just getting started on hadoop and curious what the best way in
I was curious if anyone had insight on what is the best way for

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.