Method: APIHelper::Multigettable#multiget

Defined in:
lib/api_helper/multigettable.rb

#multiget(resource, find_by: :id, param: :id, max: 10) ⇒ Object

Get multiple resources from the request by specifing ids split by ‘,’

Params:

resource

ActiveRecord::Relation resource collection to find resources from

find_by

Symbol the attribute that is used to find resources, defaults to :id

param

Symbol the request parameter name used to find resources, defaults to :id

max

Integer maxium count of returning results



66
67
68
69
70
71
72
73
74
75
# File 'lib/api_helper/multigettable.rb', line 66

def multiget(resource, find_by: :id, param: :id, max: 10)
  ids = params[param].split(',')
  ids = ids[0..(max - 1)]

  if ids.count > 1
    resource.where(find_by => ids)
  else
    resource.find_by(find_by => ids[0])
  end
end