Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

123
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda