简体   繁体   中英

How can I cache a button click on rails?

I would like to save in local cache when a user clicks a certain button. Basically a message shows up and the user clicks a button to not show the message again. I was thinking that the best way to achieve this is by saving that the user clicked the button in the local cache. How would I go about doing this? If you have a better way to achieve this functionality please let me know.

If you are talking about javascript, try localStorage

if (localStorage.getItem('user_clicked') === null) {
  alert('message');
  localStorage.setItem('user_clicked', true);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM