ADZ 學習筆記

Ruby/Rails, Startup, Life

rails 筆記 - rails 分頁 will_paginate + bootstrap + i18n

| Comments

in gem file

gem 'bootstrap-will_paginate' 
gem 'will-paginate-i18n', :git => 'https://github.com/afunction/will-paginate-i18n'

in controller

def index   
    @courses = Course.all.page(params[:page]) 
    # or 
    @courses = Course.all.page({page: @page, per_page: 20}) 
end

in view

<!-- Bootstrap style -->
<%= will_paginate(@courses) %> 

<!-- will_paginate default style -->
<%= will_paginate(@courses, :renderer => WillPaginate::ActionView::LinkRenderer) %>

https://github.com/yrgoldteeth/bootstrap-will_paginate
https://github.com/afunction/will-paginate-i18n

Comments

comments powered by Disqus