Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

90
Vistas
Setting href on javascript ignores rails root path

I have a Rails 6 application that doesn't use a regular sql-ish database, I do searches on an LDAP directory, and because of that, I don't use regular models for users, for example.

In one of my pages, I ask the user to input a person ID and then click a "Search" button, and through javascript I grab the id and pass it into the "Search" button href. As you can see here:

example.html.erb

<form class="d-flex">
    <input id="input" class="form-control me-2" placeholder="Person's ID"></input>
    <a id="search" class="btn btn-outline-success">Search</a>
</form>

example.js

const inputPerson = document.getElementById('input')
const searchPerson = document.getElementById('search')

searchPerson.addEventListener('click', () => {
  searchPerson.setAttribute("href", `/people/${inputPerson.value}`);
})

So here comes the problem: In my machine, running rails s and testing it, it works fine, as it redirects to localhost:3000/people/12345example But my website runs in an url that looks like this: shared-url.com/myappname So I expected the href on production would look like shared-url.com/myappname/people/12345example but it's actually coming up as shared-url.com/people/12345example, and of course it fails as this url does not exist at all...

I have config.relative_url_root = '/myappname' in my config/environments/production.rb, is there any other config I should have set for it to work like that? I know I could just change the javascript href, but I believe there's something I'm doing wrong.

Thanks in advance!

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda