Skip to content

A demo app using Ransack with Rails 5.1 and Ruby 2.3 to create advanced search forms.

Notifications You must be signed in to change notification settings

mgatny/ransack_demo

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ransack Demo Application

This is a quick demonstration of how you might use Ransack in a Rails 5 application to create an "advanced" search form, with nesting, etc.

The main things you'll want to note are:

  • app/models/user.rb - Demonstration of:
    • using a "ransacker" (a virtual, searchable "column") to allow searching on full names from concatenated first and last names.
    • whitelisting attributes allowed for searching using ransackable_attributes.
    • whitelisting attributes allowed for sorting using ransortable_attributes.
  • app/views/users/ - Search form and various partials used in dynamic form.
  • app/helpers/application_helper.rb - setup_search_form, which creates a Javascript search object with a grouping template, since we can't dynamically create grouping templates in Ruby (groupings can contain other groupings, would end up in infinite recursion). The rest of the methods in here are pretty much the same as the nested field helpers in Ryan Bates' Railscast #197.
  • app/assets/javascripts/search.js.coffee - CoffeeScript to handle addition/removal of fields, as well as nesting fields (adding a grouping from the previously mentioned grouping template)

Let us know if you have any questions, and happy ransacking!

About

A demo app using Ransack with Rails 5.1 and Ruby 2.3 to create advanced search forms.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 75.5%
  • HTML 15.9%
  • CSS 5.0%
  • CoffeeScript 2.0%
  • JavaScript 1.6%