Sha256: 741682b4e3184c913dddca5d0ba268d6b9515e190f72a8bb6959bc450569e2a4
Contents?: true
Size: 960 Bytes
Versions: 1
Compression:
Stored size: 960 Bytes
Contents
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 %>
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
hikari-0.5.0 | README.rdoc |