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

118
Vistas
How to call js functions defined in script tag of the erb file?

I have a layout for PDF (views/layouts/pdf.html.erb):

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <script src="https://cdn.tailwindcss.com"></script>
    <script>
      function sayHello() {
        return "HAAHAHAhAHAAH"
      }
    </script>
    <style>
    </style>
  </head>
  <body>
    <%= yield %>
  </body>
</html>

I want to use that sayHello() function inside a p tag in app/views/invoices/pdf.html.erb, which gets embedded in yield of layouts/pdf.html.erb

I tried calling sayHello() in different ways like using <%= javascript: sayHello()%> etc.. but nothing works.

I also tried keeping sayHello() in a separate file and then referencing it in javascript_pack_tag in layouts/pdf.html.erb which leads to a different error.

Is there any way that I can access that function in html.erb?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Give your paragraph a class like so:

<p class="p_class"></p>

then put this

<script>
  document.getElementsByClassName('p_class')[0].textContent = sayHello();
</script>

at the bottom of your app/views/invoices/pdf.html.erb partial.

about 4 years ago · Juan Pablo Isaza Denunciar
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