Resetting Pagination on AJAX destroy
I am using will_paginate for paginating my results. Most of my site is AJAXified. All the records in the 开发者_运维问答view can be edited/deleted in place. These records are paginated. I would like to know if there is any way to reset the pagination on AJAX destroy.
For example, say i have 20 records, with 5 records shown per page. If the user deletes a record, i would want the pagination links to reset accordingly. Also, i would have to pull in the next record onto the current page and display it in place of the deleted record. I just wanted to know if there was some gem/plugin available that could do the same. If not i would have to make one myself.
Is there any other alternative to the design approach that i am using? Perhaps something on the lines of Twitter/Buzz/Tumblr pagination? Or is there something you have come across which is better/cooler way of solving this issue?
I understand that just reloading the div holding the 5 records and the pagination is not an option.
If this is the case, on the destroy method, you could also append a new record and reload the pagination.
def destroy
# destroy record
...
#reload records for current page
@models = MyModel.paginate(:page => params[:page])
render :update do |page|
#remove record div
...
new_record_to_append = @models[MyModel.per_page - 1]
#append the last record to the page
page.insert_html(:bottom, 'content', :partial => 'my_partial', :object => new_record_to_append) if new_record_to_append
#replace pagination
page.replace 'pagination', :partial => 'pagination_partial'
end
end
精彩评论