Commit d3d8d79a5a357e959ec27a1e5e1cb55cc19099bb
1 parent
5da7a87a
Exists in
master
and in
21 other branches
api: refactoring select_filtered_collection_of
Showing
1 changed file
with
5 additions
and
4 deletions
Show diff stats
lib/noosfero/api/helpers.rb
| ... | ... | @@ -107,12 +107,13 @@ module Noosfero |
| 107 | 107 | conditions = make_conditions_with_parameter(params) |
| 108 | 108 | order = make_order_with_parameters(params) |
| 109 | 109 | |
| 110 | + objects = object.send(method) | |
| 110 | 111 | if params[:reference_id] |
| 111 | - created_at = object.send(method).find(params[:reference_id]).created_at | |
| 112 | - objects = object.send(method).send("#{params.key?(:oldest) ? 'older_than' : 'younger_than'}", created_at).where(conditions).limit(limit).order(order) | |
| 113 | - else | |
| 114 | - objects = object.send(method).where(conditions).limit(limit).order(order) | |
| 112 | + created_at = objects.find(params[:reference_id]).created_at | |
| 113 | + objects = objects.send("#{params.key?(:oldest) ? 'older_than' : 'younger_than'}", created_at) | |
| 115 | 114 | end |
| 115 | + objects = objects.where(conditions).limit(limit).order(order) | |
| 116 | + | |
| 116 | 117 | objects |
| 117 | 118 | end |
| 118 | 119 | ... | ... |