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

169
Vistas
How to run cookie only once

I have a script that I only want to run the first time the user goes to the new_profile view, so I want to save a cookie and then check if there's the cookie, if not, run the script, if yes don't run the script

I have a controller like this:

    def sign_up()
     cookies.permanent[:is_first_time] ||= true
     redirect_to new_profile
    end

And in my view I have:

<% if cookies[:is_first_time] %>
  <script>
    console.log("script loaded");
  </script>
<% end %>

Is there an option to have something like this:

<% if cookies[:is_first_time] = true %>
  <script>
    console.log("script loaded");
    cookies[:is_first_time] == false;
  </script>
<% end %>
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

I am not entirely sure if I understand what you want to do but from the example code I would guess that you actually want to do this:

<% if cookies[:is_first_time] %>
  <script>
    console.log("script loaded");
    <% cookies[:is_first_time] = false %>
  </script>
<% end %>
about 4 years ago · Juan Pablo Isaza Denunciar

0

I would suggest different naming

<% unless cookies[:script_was_loaded] %>
  <script>
    console.log("script loaded");
    <% cookies[:script_was_loaded] = true %>
  </script>
<% end %>
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