Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # This can be improved by Ruby Mixins in the long run, but this is the basics overview
- class Grouping < ActiveRecord::Base
- # Takes a gender and queries based on it
- scope :gender, -> (gender) { where: ... }
- end
- class GroupingsController < ApplicationController
- def index
- @groupings = Grouping.all
- filter_params.each do |key, value|
- # In ruby send is the way to call a method, in this case gender method/scope
- @groupings = @groupings.public_send(key, value) if key.present?
- end
- end
- private
- def filter_params
- params.slice(:gender) # One can add more params here
- end
- end
Add Comment
Please, Sign In to add comment