Guest User

Untitled

a guest
Nov 20th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. # This can be improved by Ruby Mixins in the long run, but this is the basics overview
  2.  
  3. class Grouping < ActiveRecord::Base
  4. # Takes a gender and queries based on it
  5. scope :gender, -> (gender) { where: ... }
  6. end
  7.  
  8. class GroupingsController < ApplicationController
  9. def index
  10. @groupings = Grouping.all
  11. filter_params.each do |key, value|
  12. # In ruby send is the way to call a method, in this case gender method/scope
  13. @groupings = @groupings.public_send(key, value) if key.present?
  14. end
  15. end
  16.  
  17. private
  18.  
  19. def filter_params
  20. params.slice(:gender) # One can add more params here
  21. end
  22. end
Add Comment
Please, Sign In to add comment