Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4267444
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T06:54:01+00:00 2026-05-21T06:54:01+00:00

I have this if statement in my video show view: <% if @video.user ==

  • 0

I have this if statement in my video show view:

<% if @video.user == current_user && current_user != nil && @video.comment_titles.count < 3 %>
    <%= link_to "Add Comment Title", "#", :id => "comment_title_link", :class => "edit" %>
    <%= simple_form_for @video, :remote => true do |f| %>
     <%= f.input :comment_title_names, :label => false, :placeholder => "Add a Comments Title" %>
      <%= f.button :submit, :value => 'Add', :id => 'add_comment_title' %>
      <div class='hint'>Let your listeners know what comments you want by adding a guiding title for them. Pose a question, ask for feedback, or anything else!</div>
    <% end %>
<% elsif @video.comment_titles.count == 3 && @video.user == current_user && current_user != nil  %>
    <p> You have reached your limit of comment titles. You can always add a new one by deleting one of your old ones. </p>
<% end %>

This if statement essentially evaluates @video.comment_titles.count to determine if the if statement or the elsif statement is true. I let users add comment_titles with ajax and so by the time @video.comment_titles.count == 3 is true, it won’t correctly evaluate the if statement since the if statement, which is in my video show view, is only called after a page reload.

I want the if statement to be called dynamically every time the number of comment_titles changes, which is equivalent to saying whenever the AJAX call for updating comment_titles is triggered. However, I’d rather do this on the client side than have to do it in a .js.erb file. How would I trigger this on the client side?

OK so no one has answered, so I’m assuming either I have not provided enough code, I have not been clear in what I am trying to do, or it is impossible. Which is it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T06:54:02+00:00Added an answer on May 21, 2026 at 6:54 am

    After reading your question again with your comment in mind, I assume that

    • There is a javascript event handler for the event ‘new comment title has been added’.
    • The provided fragment resides withing a container of sort e.g.<div id="add_comment_title_action">fragment</div>
    • The fragment should be refreshed every time the event handler is executed
    • You’ve seen that is possible to load the fragment by $('#add_comment_title_action').load('fragment_url') but you rather just do it within the client

    Let’s assume that the event handler looks something like

    $('#add_comment_title_form').submit(function(e) {
       e.preventDefault();
       $.post( 'url',
              { 'title': 'Lorem ispum dolor sit amet'}
       );
       updateFragment();       
    });
    

    Then you could have a function for updating the fragment

    updateFragment() {
      // Let's assume that @video.user == current_user && !current_user.nil?
      if($('.comment_title').size() < 3) {
         // NOP add something here to handle case when a title is deleted
      } else {
         $('#add_comment_title_action').html('<p> You have reached your limit of comment titles. You can always add a new one by deleting one of your old ones. </p>'); 
      }
    }
    

    How the code can be made better:

    • There should be some callback to check if the post request has succeeded and proceed accordingly
    • You could handle the two different states of the fragment by simply hiding and showing the options depending on the state (if you can assume all the users have enabled javascript and css)
    • If you decide to replace the fragment with .html(...) then the event handlers for the elements within the fragment should be bound with .live(event, handler) so that you can enable adding new comment titles after a delete has been performed

    Note that every check done in the client side must be done in the server side also.

    See history for completely different answer 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this sql statement: CREATE TABLE [dbo].[User]( [UserId] [int] IDENTITY(1,1) NOT NULL, [FirstName]
i have this MySQL statement from a search page, the user enters there postcode
I have this print statement: print <a href='#' onClick='document.getElementById(\myheader\).innerHTML=\\'.$rowQuery['keyword'].&nbsp; ·&nbsp;</a>; Unfortunately, it prints: <a
If I have this statement: ALTER TABLE RecipeBox.Recipe ADD CONSTRAINT AKRecipeBox_Recipe_Name UNIQUE NONCLUSTERED (Name)
I have this query statement and want to only get records that has a
I have this if statement that tests for the 2 conditions below. The second
I have seen this statement in many of the documention samples, like here This
REAL newbie here to Objective C and Cocoa. I have this 'if statement' if
I have kept hearing this statement. Switch..Case is Evil for code maintenance, but it
I'm learning objective-C and Cocoa and have come across this statement: The Cocoa frameworks

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.