Hey everyone, I need some help refactoring:

I am using kaminari for pagination on a rails 3 project and I have 
successfully followed the example in the documentation.

https://github.com/amatsuda/kaminari
https://github.com/amatsuda/kaminari_example/tree/ajax

As suggested in the example, my controller responds to js with index.js.erb. 
Here is the example code:

#users/index.js.erb
$('#users').html('<%= escape_javascript render(@users) %>');
$('#paginator').html('<%= escape_javascript(paginate(@users, :remote => 
true).to_s) %>');

As you can see, there is some javascript that calls the html function in the 
browser to replace the results with the output of rendering the _users 
partial.

So, everything is working at this point. My problem with this approach is 
that now I want to paginate another resource, let's say posts. Now, I have:

#posts/index.js.erb
$('#posts').html('<%= escape_javascript render(@posts) %>');
$('#paginator').html('<%= escape_javascript(paginate(@posts, :remote => 
true).to_s) %>');

Which starts smelling immediately, because I just copy,pasted and replaced 
"users", with "posts" 3 times. Now, of course, later on it's likely that 
instead of just using html to replace, I will end up using some other jquery 
effect to paint it, in which case I will have to go back to each 
index.js.erb in my application, and start the copy/past find/replace. 

Any ideas on how to refactor this and create the appropriate javascript 
dynamically?

Thanks,

--
Ylan.

-- 
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby

Reply via email to