Skip to main content
Ask A Question
You’re not receiving notifications from this thread.

How do I include a placeholder for empty notifications

General • Asked by Stan Smith

Your In-App Notification code worked perfectly.
However I'm stuck on what code to use to display a placeholder message if there aren't any notifications.

You mentioned this briefly in the episode but didn't offer an example.

Hey Stan,

You'd actually just put an if statement in the JS. If the length of the notifications > 0, display them, else, render your placeholder.

Something like this (I haven't tested this, so it may have some bugs):

  handleSuccess: (data) =>
    items = $.map data, (notification) ->
      "<a class='dropdown-item' href='#{notification.url}'>#{} #{notification.action} #{notification.notifiable.type}</a>"


    if items.length == 0
      items = "<a>No new notifications</a>"


That did it. Thanks Chris!

Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 31,575+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.