Commit 192dec3e14b13eec082c49050684a3d735d28d84

Authored by Leandro Santos
1 parent b4707ba4

API: fix reference_id parameter to avoid crash when load empty parameter

Showing 1 changed file with 6 additions and 5 deletions   Show diff stats
lib/noosfero/api/helpers.rb
... ... @@ -159,12 +159,13 @@
159 159 end
160 160  
161 161 def by_reference(scope, params)
162   - if params[:reference_id]
163   - created_at = scope.find(params[:reference_id]).created_at
164   - scope.send("#{params.key?(:oldest) ? 'older_than' : 'younger_than'}", created_at)
165   - else
  162 + reference_id = params[:reference_id].to_i == 0 ? nil : params[:reference_id].to_i
  163 + if reference_id.nil?
166 164 scope
167   - end
  165 + else
  166 + created_at = scope.find(reference_id).created_at
  167 + scope.send("#{params.key?(:oldest) ? 'older_than' : 'younger_than'}", created_at)
  168 + end
168 169 end
169 170  
170 171 def select_filtered_collection_of(object, method, params)
... ...