Guest User

Untitled

a guest
Jul 22nd, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. ## app/models/app.rb
  2. named_scope :with_client_id, lambda { |client_id|
  3. return :conditions => { :client_id => client_id } if client_id
  4. return {}
  5. }
  6.  
  7. named_scope :from_days_ago, lambda { |days|
  8. return :conditions => ['timestamp >= ?', days.to_i.days.ago] if days
  9. return {}
  10. }
  11.  
  12. ## app/controllers/app_controller.rb
  13. @apps = App.
  14. with_client_id(params[:id]).
  15. from_days_ago(params[:days]).
  16. count(:group => 'name')
Add Comment
Please, Sign In to add comment