使用 Bootstrap 分页的 Draper - 未定义的方法 'total_pages'
Draper with Bootstrap Pagination - undefined method 'total_pages'
我正在使用 Draper 来装饰我的视图并从中移出一些逻辑,但我正在努力解决这个问题 - 如何使用 Bootstrap 分页 (will_paginate
) 设置 Draper?
默认情况下我有这个:
delegate_all
从 Draper 文档中我尝试添加这个:
delegate :current_page, :per_page, :offset, :total_entries, :total_pages
但是在视图中调用分页时仍然returns出错。
我的控制器这样定义装饰和分页:
@matches = Match.all.paginate(:per_page => 10, :page => params[:page]).decorate
我的观点:
<%= will_paginate @matches, renderer: BootstrapPagination::Rails %>
更新:
class ApplicationDecorator < Draper::Decorator
def self.collection_decorator_class
PaginatingDecorator
end
end
class PaginatingDecorator < Draper::Decorator
# support for will_paginate
delegate :current_page, :total_entries, :total_pages, :per_page, :offset
end
class PlayerDecorator < ApplicationDecorator
delegate_all
decorates_association :matches
class MatchDecorator < ApplicationDecorator
delegate_all
decorates_association :players
https://github.com/drapergem/draper/issues/429
# app/decorators/application_decorator.rb
class ApplicationDecorator < Draper::Decorator
def self.collection_decorator_class
PaginatingDecorator
end
end
# app/decorators/paginating_decorator.rb
class PaginatingDecorator < Draper::CollectionDecorator
# support for will_paginate
delegate :current_page, :total_entries, :total_pages, :per_page, :offset
end
# app/decorators/whatever_decorator.rb
class WhateverDecorator < ApplicationDecorator
end
我正在使用 Draper 来装饰我的视图并从中移出一些逻辑,但我正在努力解决这个问题 - 如何使用 Bootstrap 分页 (will_paginate
) 设置 Draper?
默认情况下我有这个:
delegate_all
从 Draper 文档中我尝试添加这个:
delegate :current_page, :per_page, :offset, :total_entries, :total_pages
但是在视图中调用分页时仍然returns出错。 我的控制器这样定义装饰和分页:
@matches = Match.all.paginate(:per_page => 10, :page => params[:page]).decorate
我的观点:
<%= will_paginate @matches, renderer: BootstrapPagination::Rails %>
更新:
class ApplicationDecorator < Draper::Decorator
def self.collection_decorator_class
PaginatingDecorator
end
end
class PaginatingDecorator < Draper::Decorator
# support for will_paginate
delegate :current_page, :total_entries, :total_pages, :per_page, :offset
end
class PlayerDecorator < ApplicationDecorator
delegate_all
decorates_association :matches
class MatchDecorator < ApplicationDecorator
delegate_all
decorates_association :players
https://github.com/drapergem/draper/issues/429
# app/decorators/application_decorator.rb
class ApplicationDecorator < Draper::Decorator
def self.collection_decorator_class
PaginatingDecorator
end
end
# app/decorators/paginating_decorator.rb
class PaginatingDecorator < Draper::CollectionDecorator
# support for will_paginate
delegate :current_page, :total_entries, :total_pages, :per_page, :offset
end
# app/decorators/whatever_decorator.rb
class WhateverDecorator < ApplicationDecorator
end