RORLabNew/rorla — pull request #46 by rorlab (2014-08-25 04:30:59+00:00)
Title: favlinks#index 뷰 템플릿에 pageless 기능 추가함.

jquery.pagelss.js를 이용하여 favlinks#index 뷰 템플릿에 bottomless pagination 기능을 구현함.

``` ruby
gem 'will_paginate'
gem 'pageless-rails', github: 'rorlab/pageless-rails'
```

in application_helper.rb
``` ruby
def pageless(total_pages, url=nil, container=nil)
opts = {
:totalPages => total_pages,
:url => url,
:loaderMsg => 'Loading more pages...',
:loaderImage => image_path('load.gif')
}

container && opts[:container] ||= container

javascript_tag("$('#{container}').pageless(#{opts.to_json});")
end
```

in favlinks_controller.rb
``` ruby
def index
@favlinks = @bundlelink ? @bundlelink.favlinks : (params[:whose] ? Favlink.whose(current_user) : Favlink.shared)
@favlinks = @favlinks.paginate(page: params[:page], per_page: 3)
if request.xhr?
sleep(3)
render :partial => @favlinks
end
end
```

in views/favlinks/index.html.erb
``` erb

<%= params[:whose] ? "My Favlinks" : "All Favlinks" %>

<%= "of #{@bundlelink.title}" if params[:bundlelink_id] %>
(<%= @favlinks.total_entries %>)
<%= link_to icon('remove-circle'), favlinks_path if params[:bundlelink_id] %>

<%= render @favlinks %>

<%= will_paginate @favlinks %>
<%= pageless(@favlinks.total_pages, favlinks_path, '#favlinks') %>
```