Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

167
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!