简体   繁体   中英

rails jquery popup if user not logged in

trying to have a simple box popup if a user has been on site for certain duration (3 seconds for testing) and they're not logged in.

It works fine, but it's still popping up even when a user is logged in, and that shouldn't be case.

the HAML:

.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?

the coffescript:

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

When I console.log the $("#user_id").val() it always says it's undefined even when I'm logged in

the css (not the issue):

.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;
}

The haml code for setting the :id is not correct; so it is not being set, and hence $("#user_id").val() is evaluating to undefined in all cases.

Try:

haml:

.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?

coffeescript:

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

setTimeout signupPopUp, 3000

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