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 572713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:38:50+00:00 2026-05-13T13:38:50+00:00

I am currently implementing a blog-like site using Ruby on Rails. Each Post has

  • 0

I am currently implementing a blog-like site using Ruby on Rails. Each “Post” has some comments. Currently I only have the latest 5 comments load, but I want to implement a hyperlink that would load the rest of the comments. Unfortunately with my current implementation, all I get is a bunch of junk spit out.

Before

Comments

Posted 7 minutes ago 
New

Posted 1 day ago 
Comment 3

Posted 1 day ago 
Comment 2

Posted 1 day ago 
Comment 1

Posted 1 day ago 
This is a new comment

View more comments

After Click ‘View more comments’

Comments

try { Element.insert("comments", { bottom: "
\n
\n Posted 1 day ago\n 
\n Comment 2\n

\n
" }); Element.insert("comments", { bottom: "
\n
\n Posted 1 day ago\n 
\n Comment 3\n

\n
" }); Element.insert("comments", { bottom: "
\n
\n Posted less than a minute ago\n 
\n New\n

\n
" }); Element.hide("morecomments"); } catch (e) { alert('RJS error:\n\n' + e.toString()); alert('Element.insert(\"comments\", { bottom: \"
\\n
\\n Posted 1 day ago\\n 
\\n Comment 2\\n

\\n
\" });\nElement.insert(\"comments\", { bottom: \"
\\n
\\n Posted 1 day ago\\n 
\\n Comment 3\\n

\\n
\" });\nElement.insert(\"comments\", { bottom: \"
\\n
\\n Posted less than a minute ago\\n 
\\n New\\n

\\n
\" });\nElement.hide(\"morecomments\");'); throw e }

The post’s show.html.erb has:

<div id="morecomments">
  <%= link_to_remote "View more comments", :url=>{:action=>'morecomments',:post_id=>@post.id},:update=>'comments' %>
</div>

In my post controller I have

def morecomments
  @post = Post.find(params[:post_id])
  @comments = @post.comments.values_at(Range.new(5, @post.comments.size-1))
  respond_to do |format|
    format.html {redirect_to @post.comments}
    format.js
  end
end

And finally my morecomments.js.rjs:

@comments.each do |p|
  page.insert_html :bottom, :comments, :partial => p
end
page.hide 'morecomments'

I’m really new to Rails, and I don’t really know about all of the meta magic rails is doing in the background. Any help would be awesome.

Thank you!

  • 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-13T13:38:51+00:00Added an answer on May 13, 2026 at 1:38 pm

    Your problem is that you’re mixing concepts. You get your choice of using link_to_remote with the :update option, or using RJS. Not both.

    When you use link_to_remote with the :update option your view expects to receive a chunk of html which will replace the inner html of the DOM element matching the id provided to :update. In your case, this is the comments div.

    Your format .js section is rendering the rjs template because you haven’t told it to do anything else and it’s generating javascript, which the link_to_remote treats as html uses it to replace the comments div.

    You have two solutions:

    1. Use link_to_remote with :update

      Your view doesn’t change, and your rjs file goes unused. To implement this fix replace the foramt.js line in your controller with this:

       format.js { render :partial => 'comments', :collection => @comments}
      
    2. Use RJS

      In this solution, your controller doesn’t change. all you have to do is remove the , :update =>'comments' from your link_to_remote call.

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

Sidebar

Ask A Question

Stats

  • Questions 532k
  • Answers 532k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer My current solution is to have the FormEncode rules in… May 17, 2026 at 12:06 am
  • Editorial Team
    Editorial Team added an answer Webdzinez To use it, an app on the Android device… May 17, 2026 at 12:06 am
  • Editorial Team
    Editorial Team added an answer Wow - that is a massive question, and one that… May 17, 2026 at 12:06 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm implementing a Blog with Post and votable Comments. When loading a Post, I
I'm working on a Rails application that's kind of like a blog. Users create
I've been creating a blog using tutorials around the web and I have a
I'm currently implementing a RESTful API (nothing serious, just for a blog engine i'm
Currently implementing vectorial interface elements on iOS is very peculiar, UIImage advertises support only
In my blog application, some posts appear as excerpts -- i.e., the user sees
I am currently working on a application that will be implementing user customizable widgets
I'm currently working on implementing the public API of our web application. The application
I am implementing a RESTful web service that currently handles JSON and needs to
Hey, I'm currently looking for various methods of implementing collision response in 2D video

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.