0.0
No commit activity in last 3 years
No release in over 3 years
Searching form and sorting query builder
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

Runtime

>= 3.0
 Project Readme

kashiwamochi

Build Status

Kashiwamochi is a minimal searching extension for Rails 3 and 4.

Installation

gem 'kashiwamochi'
# gem 'kashiwamochi', :git => 'git://github.com/mashiro/kashiwamochi.git'

Getting started

In your controllers

Build query

# use before_filter.
before_filter :build_query!, :only => [:index]

# or write directly.
def index
  @q = Kashiwamochi.build(params[:q])
end

Use query

# basic
@users = User.where(:name => @q.name)
             .order(@q.sorts(:age))

# mapped order
@users = User.where(:name => @q.name)
             .order(@q.sorts(:age => 'years'))

In your views

# _search.html.haml
= search_form_for @q do |f|
  = f.text_field :name
  = f.submit

# _list.html.haml
%table
  %thead
    %tr
      %th= sort_link_to @q, :name, 'User name'
  %tbody
    ...

With simple_form

= search_form_for @q, :form_method => :simple_form_for do |f|
  = f.input :name
  = f.button :submit

CSS

/* Show the sort direction. */
.sort_link.asc:after  { content: " \25b2"; }   
.sort_link.desc:after { content: " \25bc"; }   

Copyright

Copyright (c) 2011 mashiro