Adding Results via jQuery and avoiding duplication in will_paginate
I am using will_paginate to paginate the comments in my Rails 3 app and it is working great.
Currently, I am displaying 10 comments per page. Now, when I add开发者_如何学运维 a comment using javascript (jQuery) and append it on the top of the page it will show 11 comments.
However, the links have not refreshed. So, when I click on next page link, the last comment on previous page is displayed again.
Is there a way I can avoid this duplication of result?
Will I have to refresh the links every time I create and append a new comment using jQuery?
One option would be to drop the last comment off of the page at the same time that you're adding the new one to the top. If you used some jQuery effects, you could make it look like the bottom comment was dropping off the page at the same time that the top comment was being added.
That way when the user sees the old 10th comment at the top of page two, it will seem logical.
I agree with polarblau that this is better handled in the view. To handle it in the controller you'd need to figure out a way to offset the finder by +1 which seems like it would be a LOT more effort.
精彩评论