Project

hikari

0.0
No commit activity in last 3 years
No release in over 3 years
Hikari allows sorting in Rails projects based on fields or scopes. Sorting can be done across models via scopes.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 1.0.0
>= 0
~> 3.1.0
~> 1.3

Runtime

>= 4.0.0
>= 4.0.0
 Project Readme

Hikari helps create sorting links for Ruby on Rails applications. It also allows sorting on associated models via scopes and default orders to be provided in the view. It pairs nicely with Kaminari, but only works with ActiveRecord at the moment.

Simple example

class Post < ActiveRecord::Base
  belongs_to :author, class_name: 'User'

  scope :by_author_last_name, -> {
    joins(:author).order("users.last_name")
  }
end
class User < ActiveRecord::Base
  has_many :posts
end

app/controllers/posts_controller.rb

def index
  @posts = Post.sort(params[:sort], 'title ASC')
end

app/views/posts/index.html.erb

<%= link_to_sorted 'Title', :title %>

<a href="/posts?sort=title_asc" class="sortable">Title</a>

If a field matching the sort parameter is not found Hikari will attempt to apply an ActiveRecord scope that is defined on the model. To sort Posts by Author:

<%= link_to_sorted 'By Author', :by_author_last_name %>