diff --git a/docs/customizing_dashboards.md b/docs/customizing_dashboards.md index d7f68e4e05..5138a026c5 100644 --- a/docs/customizing_dashboards.md +++ b/docs/customizing_dashboards.md @@ -113,8 +113,8 @@ association `belongs_to :country`, from your model. **Field::HasMany** -`:limit` - Set the number of resources to display in the show view. Default is -`5`. +`:limit` - The number of resources (paginated) to display in the show view. To disable pagination, +set this to `0` or `false`. Default is `5`. `:sort_by` - What to sort the association by in the show view. diff --git a/lib/administrate/field/has_many.rb b/lib/administrate/field/has_many.rb index b223ba807f..804ef74eda 100644 --- a/lib/administrate/field/has_many.rb +++ b/lib/administrate/field/has_many.rb @@ -45,6 +45,10 @@ def limit options.fetch(:limit, DEFAULT_LIMIT) end + def paginate? + limit.respond_to?(:zero?) ? limit.zero? : limit.present? + end + def permitted_attribute self.class.permitted_attribute( attribute, @@ -53,12 +57,15 @@ def permitted_attribute end def resources(page = 1, order = self.order) - resources = order.apply(data).page(page).per(limit) + resources = order.apply(data) + if paginate? + resources = resources.page(page).per(limit) + end includes.any? ? resources.includes(*includes) : resources end def more_than_limit? - data.count(:all) > limit + paginate? && data.count(:all) > limit end def data