如果用户未登录,则弹出 Rails jQuery 弹出窗口

rails jquery popup if user not logged in

本文关键字:Rails jQuery 窗口 用户 登录 如果      更新时间:2023-09-26

如果用户已经在现场停留了一定时间(测试时间为 3 秒)并且他们没有登录,则尝试弹出一个简单的框。

它工作正常,但即使用户登录,它仍然会弹出,而这种情况不应该是这样。

哈姆尔:

.signuppopup{:id => if current_user then "user_id#{current_user.id}" else "user_id#{0}" end}
  %h1 You've been browsing the site for a while, why not sign up?

咖啡标本:

signupPopUp = ->
  $(".signuppopup").css "display", "block" unless $("#user_id").val() is 0
  return
setTimeout signupPopUp, 3000

当我控制台时.log$("#user_id").val() 它总是说它未定义,即使我登录了

CSS(不是问题):

.signuppopup{
  opacity:0.92;
  position: absolute;
  text-align: center;
  top: 35%;
  left: 35%;
  height: 30%;
  width: 30%;
  background: #69EAB8;
  padding-top: 20px;
  display: none;
  overflow-y: auto;
}

用于设置:idhaml代码不正确;因此它没有被设置,因此$("#user_id").val()在所有情况下都评估为未定义。

尝试:

哈姆尔:

.signuppopup{:id => (if current_user then "signed_in" else "not_signed_in")}
  %h1 You've been browsing the site for a while, why not sign up?

咖啡脚本:

signupPopUp = ->
  $(".signuppopup").css "display", "block"  if $("#signed_in").length > 0
  return
setTimeout signupPopUp, 3000