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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:58:33+00:00 2026-06-13T11:58:33+00:00

I have some plain HTML that provides some functionality when a link is clicked.

  • 0

I have some plain HTML that provides some functionality when a link is clicked. I want to clean this up so that it is handled in a way that conforms to Ruby/Rails coding style. I tried messing with link_to helpers but couldn’t figure out a clean way to handle this situation.

<p>...or <a id="set_current_location" href="#">Use Current Location</a></p>

<script>
$(function(){
    $('#set_current_location').on('click', function(e){
        e.preventDefault();
        navigator.geolocation.getCurrentPosition(function(position) {
            $.ajax({
              type: 'POST',
              url: '<%= set_location_path %>',
              data: {
                latitude: position.coords.latitude,
                longitude: position.coords.longitude
              },
              async: false
            });
        })
    });
});
</script>

Update: I’ve actually moved the javascript into a coffeescript file, so that’s not really my question. I’m really just wondering if this looks like a rails-like way to approach this problem.

  • 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-13T11:58:34+00:00Added an answer on June 13, 2026 at 11:58 am

    The “rails way” would be to leave your javascript out of your view, using unobtrusive javascript in a separate file. At first glance, your code is fine – just move your “script” stuff into a .js file.

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

Sidebar

Related Questions

I have an html document formatted this way: <p> some plain text <em>some emphatized
I have plain HTML file and I want to include some JSTL tags in
I have some pages on my site that are plain HTML pages, but I
I have an XSLT file generating plain HTML. I need to wrap some elements
I have some arbitrary pixel data that I want to save as a PNG.
I have some plain text and html. I need to create a PHP method
I have a problem... I have some long hyperlinks that are plain text that
I have some Plain Text/HTML Content like so: Title: Lorem ipsum dolor sit amet,
I have some HTML DIV elements that contain a narrative style of form. For
I have some javascript that looks like this: var sel = '<option value={value} {selected}>{name}</option>';

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.