coreyjs / rogue_filter

Easy ActiveRecord filtering with search parameters

Repository from Github https://github.comcoreyjs/rogue_filterRepository from Github https://github.comcoreyjs/rogue_filter

Build Status

RogueFilter

Rogue Filter makes it easy to add scopes to ActiveRecord models. This is helpful when chaining together multiple scopes on models that have many search parameters.

Usage

model.rb

class Car < ApplicationRecord
  acts_as_filterable

  scope :rogue_name, -> (name) { where name: name }
end

All custom scopes that you want to get called must be prefixed with rogue_.

controller.rb

Car.filterable({name: 'Corey'})
  • RogueFilter will define the class method filterable on all models that call acts_as_filterable

Installation

Add this line to your application's Gemfile:

gem 'rogue_filter'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rogue_filter

Contributing

Contribution directions go here.

License

The gem is available as open source under the terms of the MIT License.

Mention

This was a learning project, idea was taken from https://www.justinweiss.com/articles/search-and-filter-rails-models-without-bloating-your-controller/ .

About

Easy ActiveRecord filtering with search parameters

License:MIT License


Languages

Language:Ruby 77.6%Language:HTML 16.8%Language:JavaScript 3.4%Language:CSS 2.2%