I am trying to ajaxify my will_pagniate pagination in rails. I want the old page to disappear and the new page to fade.
Here is the relevant part of my controller:
respond_to do |format| format.html
The above partial:
<div id="page"> <%= will_paginate %> <div id="posts"> <%= render @posts %> </div> <%= will_paginate %> </div>
And the corresponding part of application.js:
document.observe("dom:loaded", function() { // the element in which we will observe all clicks and capture // ones originating from pagination links var container = $(document.body) if (container) { var img = new Image img.src = '/images/spinner.gif' function createSpinner() { return new Element('img', { src: img.src, 'class': 'spinner' }) } container.observe('click', function(e) { var el = e.element() if (el.match('.pagination a')) { el.up('.pagination').insert(createSpinner()) target = $('posts') new Effect.fade(target, { duration: 0.3, afterFinish: function() { new Ajax.Request(el.href, { method: 'get', onSuccess: function(){ new Effect.Appear(target, {duration:0.3})} }) }}) e.stop() } }) } })
The script seems to be killed on this line,
new Effect.fade(target, { duration: 0.3, afterFinish: function()
because I see spinner.gif running, then it doesnβt disappear, and the page refreshes normally. I have ajax work before I tried to add Effect.Fade and Effect.Appear.
Is this the right way? Should I put effects in the controller instead?
source share