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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6c8bb9d9cd7cbd2160b42329feecf0c6989069d2
4
- data.tar.gz: f78351cc3a133a7ae0daaa3ac89849580e1ff32a
3
+ metadata.gz: e01cbbb9f3c94c956178c6621ba641bd5553b0fe
4
+ data.tar.gz: 6b24e29afa7582fad977af32e080a2935abd8e04
5
5
  SHA512:
6
- metadata.gz: e2dddc0491636c11a14e9109aca73939ae216e69ad2c00ecb845c8d95b834878097bae7dad0a7107badb2fd273c77e887d1233887137fcdfa654ea76889d4d65
7
- data.tar.gz: 71f5460fb2496b7f89a1dd3f461fddadb13ed553e342cab0fd6d92e104c24d488b36ee132f29a7cc3092363f9a6b16d7fa4e8f45e0d06c34ab1ba2d4612a4248
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 by default, you can set another one by:
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: :author)
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
- <%= sortabl_link :author, id: 'author-column', class: 'author-column' do %>
70
- <p>Author</p>
71
- <% end %>
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, id: 'author-column', class: 'author-column', sort_param: :my_custom_sort_param %>
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])
@@ -50,7 +50,7 @@ module Sortabl
50
50
  end
51
51
 
52
52
  # Order class object
53
- order((sort_params[args[0][:sort_by]] or "#{order_by_default} asc"))
53
+ order((sort_params[args[0][:sort_by]] or order_by_default))
54
54
  end
55
55
 
56
56
  end
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Sortabl
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sortabl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frederic Walch