Skip to content

Ezveus/trestle-search-plus

 
 

Repository files navigation

Trestle Search Plus (trestle-search-plus)

Search plugin for the Trestle admin framework

Getting Started

These instructions assume you have a working Trestle application. To integrate trestle-search-plus, first add it to your application's Gemfile:

gem 'trestle-search-plus'

Run bundle install, and then restart your Rails server.

To enable search capabilities within an admin resource, define a search block:

Trestle.resource(:articles) do
  search do |query|
    if query
      Article.where("title ILIKE ?", "%#{query}%")
    else
      Article.all
    end
  end
end

The search block accepts one or two parameters; the first is the string value of the search query. The second, optional parameter is the full params hash. The block should return a chainable scope.

The search block overrides the default (or custom) collection block. However the original collection block can be called to avoid redefining scopes. For example:

Trestle.resource(:articles) do
  collection do
    Article.order(created_at: :desc).includes(:author)
  end

  search do |q|
    q ? collection.where("title ILIKE ?", "%#{q}%") : collection
  end
end

Caveat: this gem is a fork of trestle-search by Sam Pohlenz. Both gems use the same namespaces and it is advised to not have both in your Gemfile.

Integration Examples

  1. ActiveRecord (ILIKE)
  2. PgSearch
  3. Chewy
  4. Sunspot

License

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

About

Search plugin for the Trestle admin framework

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 78.6%
  • HTML 14.0%
  • JavaScript 4.3%
  • CSS 1.7%
  • SCSS 1.4%