You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

filterable_sortable

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

filterable_sortable

0.0.7
bundlerRubygems
Version published
Maintainers
1
Created
Source

FilterableSortable

Gem generates :filtered and :sorted scopes, can be easily used for building admin namespace or other filterable sortable architecture.

Installation

Add this line to your application's Gemfile:

gem 'filterable_sortable'

And then execute:

bundle

Or install it yourself as:

gem install filterable_sortable

Usage

Models

First of all include module into ActiveRecord::Base inherited class

include FilterableSortable

Controllers

In controllers add scopes to index action. I use 'will_paginate' gem, so here is method *.paginate(...)

@posts = Post.filtered(params[:filter]).ordered(params[:order]).paginate(page: params[:page], per_page: params[:per_page])

Views

Filtering and sorting

In views you can use links with params for order and filter. Example in Haml.

= link_to 'Name', posts_path(filter: {custom: :name}, order: {field: :name, direction: :ASC})

Searching

Simple search is also acts as filter, works as scope, already defined in gem, so enjoy it.

= form_tag posts_path do
    = text_field_tag :'filter[search]'

Contributing

  • Fork it
  • Create your feature branch (git checkout -b my-new-feature)
  • Commit your changes (git commit -am 'Add some feature')
  • Push to the branch (git push origin my-new-feature)
  • Create new Pull Request

FAQs

Package last updated on 08 Feb 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts