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

  • Home
  • SEARCH
  • 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 8279819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:27:09+00:00 2026-06-08T09:27:09+00:00

UPDATE I have mange to get it working by changing the Model call from

  • 0

UPDATE

I have mange to get it working by changing the Model call from

@comments = VideoComment.all(:conditions => { :video_id => @video.id}, :limit => 5, :order => :created_at) 

@comments = VideoComment.last(5).reverse

It works, but it gives me the last video comments from all the videos whereas I only want those from the current video (@video.id).

Any clue on how to do that?


I have a Videocontroller and a VideoComments controller which manages the comments for the Video controller. I am trying to make my remote form update the comments list with ajax but it does not seem to work. Can you find what I did wrong?

HTML code of the show page :

- if current_user
    #comment-form
      = render 'video_comments/comment_form'
  %ul
    #comments
      = render @comments

video_comments/_comment_form.html.haml

= form_for current_user.video_comments.build(:video_id => params[:id]), :remote => true do |f|
  .form-fields
    .comment-content
      = f.text_area :content, rows:2
    = f.hidden_field :video_id
    = f.hidden_field :user_id
    .submit-form
      = f.submit "Add a comment", :class => "btn btn-default "

The Video_Commentscontroller createaction :

 def create
    @comment = VideoComment.create(params[:video_comment])
    @video = @comment.video
    @comments = VideoComment.all(:conditions => { :video_id => @video.id}, :limit => 5, :order => :created_at) 
    render :toggle      
 end

The toggle.js.erb file which manages the page changes :

$("#comment-form").html("<%= escape_javascript render 'comment_form' %>");
$("#comments").html("<%= escape_javascript render @comments %>");
  • 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-06-08T09:27:12+00:00Added an answer on June 8, 2026 at 9:27 am

    If you are using Rails 3 you can do

    @comments = VideoComment.where(:video_id => @video.id).order(:created_at).limit(5) 
    

    Or if you have relations properly defined you can also do

    @comments = @video.comments.order(:created_at).limit(5)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

UPDATE I have updated my code in response to @MichaelRushton comments. I am now
I am working on inserting data into our UniData server from .net. I have
Update I have just tried Pinning my site to the Taskbar again (after removing
UPDATE: I have somewhat resolved the issue. Just in case if anyone runs in
UPDATE - I have fixed some mistakes in the code below and the images
I have update panel that content check box, textbox, 3 DropDownList with CascadingDropDown extender.
I have scenario, I have two update panels on the page (both have update
I use oracle 10. I have update statement like that : update table1 t1
I have two update panels on a page. And I want to update both
I have to update different server data which takes huge time. I have to

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.