Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mikamai/will_sortate
https://github.com/mikamai/will_sortate
Last synced: 22 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/mikamai/will_sortate
- Owner: mikamai
- License: mit
- Created: 2013-05-28T08:22:02.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2013-06-06T07:43:15.000Z (over 11 years ago)
- Last Synced: 2024-04-14T19:56:50.783Z (9 months ago)
- Language: Ruby
- Size: 133 KB
- Stars: 1
- Watchers: 29
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# WillSortate
will_sortate is [will\_paginate](https://github.com/mislav/will_paginate) for sorting. It helps you manage the sorting of an ActiveRecord dataset.
## Installation
Add this line to your application's Gemfile:
gem 'will_sortate'
And then execute:
$ bundle
Or install it yourself as:
$ gem install will_sortate
## Usage
### In your controller
```ruby
@products = Product.sortate(params[:sort], 'my_field_asc')
```The first param given to the `sortate` named scope is the sort argument, while the second param is the default sort argument.
The sort argument indicates the column and order direction, so `my_field_asc` will do an `ORDER BY my_field ASC`
### In your views
```erb
<%= sortate_link_to 'One Field', @shorties, :one_field, options %>
<%= sortate_link_to @shorties, :my_field, options do %>
My Field
<% end %>
```The options argument is optional and will be passed to the underlying link_to. In addition you can pass in the options hash:
- `default_sort_order`: the default sort order to use (`asc` or `desc`).
E.g.:
```erb
<%= sortate_link_to 'My Field', @shorties, :my_field, class: 'sort_link', default_sort_order: 'desc' %>
```## TODO
Tests!
## Contributing
1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request