Created
July 19, 2012 09:34
-
-
Save jeroenr/3142686 to your computer and use it in GitHub Desktop.
Make will_paginate generate ajax links
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ApplicationHelper | |
def paginate(collection, params= {}) | |
will_paginate collection, params.merge(:renderer => RemoteLinkPaginationHelper::LinkRenderer) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source 'https://rubygems.org' | |
gem 'rails', '3.2.3' | |
# Gems used only for assets and not required | |
# in production environments by default. | |
group :assets do | |
gem 'sass-rails', '~> 3.2.3' | |
gem 'coffee-rails', '~> 3.2.1' | |
# See https://github.com/sstephenson/execjs#readme for more supported runtimes | |
gem 'therubyracer', :platform => :ruby | |
gem 'uglifier', '>= 1.0.3' | |
end | |
gem 'jquery-rails' | |
gem 'will_paginate', '~> 3.0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="page_links"> | |
<%= paginate @results %> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module RemoteLinkPaginationHelper | |
class LinkRenderer < WillPaginate::ActionView::LinkRenderer | |
def link(text, target, attributes = {}) | |
attributes['data-remote'] = true | |
super | |
end | |
end | |
end |
Thanks to @tarmotalu
Thanks a lot! It's really cool!!!
For those who want to use it with the bootstrap gem:
module RemoteLinkPaginationHelper
class LinkRenderer < WillPaginate::ActionView::BootstrapLinkRenderer
def link(text, target, attributes = {})
attributes['data-remote'] = true
super
end
end
end
One line in my js.erb file (e.g., index.js.erb) and will_paginate started working with ajax. Here it is: $('.pagination a').attr('data-remote', 'true');
Steve you're a rockstar!!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks to @tarmotalu