views:

144

answers:

2

I'm now developing comment system for my site on Ruby on Rails. I try to make comments to be appeared when user click on SEE MORE button. I see this is not like we do in pagination, so I need your little help guys!

When all comments have been displayed, the SEE MORE button should be removed from the page.

+1  A: 

When the page loads, include a Javascript variable to indicate the "last item seen" or a time stamp (which I believe Twitter does as it orders the tweets in date order). You then have a Javascript function initiated by the setTimeout function which polls your server with this timestamp.

Your server then looks up to see if there has been any more posts since that point and if there has been, returns the number of results to the Javascript with an instruction to show a "See more" prompt - it also includes a new timestamp (if there are no new results, it just returns a timestamp).

Clicking on the "See more" prompt will then load in the new posts via Javascript, display them via the DOM and then reset the Javascript variable and repeat the process.

Of course, how you actually implement this will depend on how your data is structured, the server software you are actually using, what you actually want to do on the client side if there are new posts and then have often you want to "poll" the server for new responses (baring in mind more frequent polls will increase your server load).

Richy C.
good alghoritm, but sometimes code implementation can be so difficult without code sample, thanks
Anton
What Javascript framework (if any) are you using, what backend are you using (PHP/RoR/Perl etc), how is your database structured? All these items will depend on how the code is written.
Richy C.
A: 

Have you checked out this JQuery plugin. I believe it does pretty much exactly what you're looking for, and the example shows how to set it up using Rails. It's styled on the Facebook "Show more posts" pagination but this is basically the same as the "More" posts pagination as used by Twitter.

thor
I can't get it to work with my application.I use will_paginate and I included jquery.bottomlesspagination.js,but button show more doesn't appear.I consider the problem in jquery.bottomlesspagination.js
Anton
Could somebody help me?
Anton