sortabl 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +18 -6
- data/lib/sortabl/sortabl_core.rb +1 -1
- data/lib/sortabl/sortabl_helper.rb +1 -0
- data/lib/sortabl/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e01cbbb9f3c94c956178c6621ba641bd5553b0fe
|
4
|
+
data.tar.gz: 6b24e29afa7582fad977af32e080a2935abd8e04
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06d49735d1368a0a14ed9c6b67551c696974078fa176a8aca779116f2a11b70991e7a416824277eb58ffcaf2f1407199787225caa7c634119b1d254f9543b411
|
7
|
+
data.tar.gz: d84f32c0b91703ad7aece129cfbc1a73ff8496cb284d1015200062ef3ce254345bcc5fda39b56247e4838829bdff6183305248a0813902ecd70bcda44a2f291d
|
data/README.md
CHANGED
@@ -14,16 +14,26 @@ gem 'sortabl'
|
|
14
14
|
|
15
15
|
### Controller
|
16
16
|
|
17
|
+
#### Default
|
18
|
+
|
17
19
|
```ruby
|
18
20
|
@posts = Post.sortabl(sort_by: params[:sortabl])
|
19
21
|
```
|
20
22
|
|
21
|
-
And that's it! Records will be sorted by permitted parameter `:sortabl`. If parameter `:sortabl` isn't permitted, records will be sorted by primary key. If you don't want to sort by primary key
|
23
|
+
And that's it! Records will be sorted by permitted parameter `:sortabl`. If parameter `:sortabl` isn't permitted, records will be sorted by primary key. If you don't want to sort by primary key as default, you can set another one by:
|
22
24
|
|
23
25
|
```ruby
|
24
|
-
@posts = Post.sortabl(sort_by: params[:sortabl], default:
|
26
|
+
@posts = Post.sortabl(sort_by: params[:sortabl], default: 'author asc')
|
25
27
|
```
|
26
28
|
|
29
|
+
Even default multiple columns sort is possible:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
@posts = Post.sortabl(sort_by: params[:sortabl], default: 'author asc, created_at desc')
|
33
|
+
```
|
34
|
+
|
35
|
+
#### Limeted Attributes
|
36
|
+
|
27
37
|
Permitted values can be an attribute of model class, followed by `_asc` or `_desc`. For example: `sort: :author_asc`
|
28
38
|
If there's an attribute permitted which doesn't exist in model, it falls back to sort by `default` key. Attributes can be limited with `only` and `except`. For example:
|
29
39
|
|
@@ -36,6 +46,8 @@ If there's an attribute permitted which doesn't exist in model, it falls back to
|
|
36
46
|
|
37
47
|
### View
|
38
48
|
|
49
|
+
#### Link Helper
|
50
|
+
|
39
51
|
There's also a link helper, which generates needed urls. It works just like you would expect from rails default link_to helper. But instead of hand over a path, just place the desired column name. The helper will do the rest for you:
|
40
52
|
|
41
53
|
```erb
|
@@ -66,9 +78,9 @@ There's also a link helper, which generates needed urls. It works just like you
|
|
66
78
|
This link helper can be placed anywhere in the view. There is no need, that it has to be placed in table head. Furthermore you can use `sortabl_link` as block too.
|
67
79
|
|
68
80
|
```erb
|
69
|
-
|
70
|
-
|
71
|
-
|
81
|
+
<%= sortabl_link :author, id: 'author-column', class: 'author-column' do %>
|
82
|
+
<p>Author</p>
|
83
|
+
<% end %>
|
72
84
|
```
|
73
85
|
|
74
86
|
#### Parameter
|
@@ -77,7 +89,7 @@ By default, `sortabl_link` will generate `:sortabl` as parameter into the url. I
|
|
77
89
|
|
78
90
|
```ruby
|
79
91
|
# In view
|
80
|
-
<%= sortabl_link 'Author', :author,
|
92
|
+
<%= sortabl_link 'Author', :author, sort_param: :my_custom_sort_param %>
|
81
93
|
|
82
94
|
# In controller
|
83
95
|
@posts = Post.sortabl(sort_by: params[:my_custom_sort_param], only: [:title, :author])
|
data/lib/sortabl/sortabl_core.rb
CHANGED
@@ -6,6 +6,7 @@ module Sortabl
|
|
6
6
|
#
|
7
7
|
def sortabl_link(name = nil, attribute = nil, html_options = nil, &block)
|
8
8
|
html_options, attribute, name = attribute, name, block if block_given?
|
9
|
+
html_options = html_options || {}
|
9
10
|
|
10
11
|
# Support custom sort_param
|
11
12
|
# If sort_param isn't given, fall back to :sortabl as param
|
data/lib/sortabl/version.rb
CHANGED