SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2005
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    IF statements in RJS files? I Need flow control!

    I have a comments system working and ready. When the page is loaded and there aren't any comments, I have:

    <&#37; if @comments_submitted.empty? %>
    <br>
    <center><b><span id="nocomments">No one has commented yet. Be the first!</span></b></center>
    <br>
    <% else %>
    The previous code creates an ID for my RJS file to remove when a comment is added:
    page.replace_html 'nocomments', ""
    Obviously, I need some sort of flow control! Because when there are comments, the "nocomments" span ID is not there. This throws an error, since there is no ID for myRJS file to replace!

  2. #2
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The most reliable way is to insert an empty span with id="nocomments" in the case that there already are comments. You can check for comments in your RJS with normal Ruby ifs, but this isn't reliable because it's possible that other users posted comments while this person was posting his comment.

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2005
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ahh thanks, I just thought of that right before I looked at your post.

    I don't know why I didn't think of that sooner


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •