Skip to content

Commit

Permalink
Merge pull request #2206 from cenit-io/develop
Browse files Browse the repository at this point in the history
Limit zero option
  • Loading branch information
macarci committed Aug 14, 2018
2 parents 447c9d4 + bc1350d commit 752bc7b
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions app/controllers/api/v3/api_controller.rb
Expand Up @@ -65,17 +65,20 @@ def index
item.default_hash(@template_options)
end
count = items.count
{
json: {
total_pages: (count * 1.0 / get_limit).ceil,
current_page: page,
count: count,
items: items_data,
data_type: {
(@template_options[:raw_properties] ? :_id : :id) => klass.data_type.id.to_s
}
json = {
current_page: page,
count: count,
items: items_data,
data_type: {
(@template_options[:raw_properties] ? :_id : :id) => klass.data_type.id.to_s
}
}
if get_limit > 0
json[:total_pages] = (count * 1.0 / get_limit).ceil
end
{
json: json
}
else
{
json: { error: 'no model found' },
Expand Down Expand Up @@ -295,9 +298,9 @@ def create_user_with(data)
def get_limit
unless @limit
limit_option = @criteria_options.delete(:limit)
limit = (@criteria.delete(:limit) || limit_option).to_i
limit = (@criteria.delete(:limit) || limit_option || Kaminari.config.default_per_page).to_i
@limit =
if limit < 1
if limit < 0
Kaminari.config.default_per_page
else
[Kaminari.config.default_per_page, limit].min
Expand Down

0 comments on commit 752bc7b

Please sign in to comment.