ransack_memory 0.0.9 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -5
- data/app/controllers/concerns/ransack_memory/concern.rb +4 -4
- data/lib/ransack_memory/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee63c846270102691c62cd2a7af77912d7aa7651
|
4
|
+
data.tar.gz: 8dd719ca19c83f10078157448a329f56ed959d9b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 444c11b00620bd325023254a05b48ea80bd53dd527164c0a6db96dc880bbf9098e0049fc49e7ab68ea3e98369febb53db37571e00497a8ba9e7df14b6f789c90
|
7
|
+
data.tar.gz: fdd5cebf99c78325ad1f0744fd41ffbdf03f5a4d617dd0434e767e969cc2b84ebca9326ce1dd3e5024400c3b383e49e3c988e7a7538a07dead13344bc84534ab
|
data/README.md
CHANGED
@@ -9,6 +9,12 @@ Add this line to your application's Gemfile:
|
|
9
9
|
gem 'ransack_memory'
|
10
10
|
```
|
11
11
|
|
12
|
+
Run the generator
|
13
|
+
|
14
|
+
```shell
|
15
|
+
rails generate ransack_memory
|
16
|
+
```
|
17
|
+
|
12
18
|
Add this line to your basic controller (typically ApplicationController):
|
13
19
|
|
14
20
|
```ruby
|
@@ -27,12 +33,12 @@ Add this in your views where you have search forms. This is clear button, which
|
|
27
33
|
You can pass any of link attributes:
|
28
34
|
|
29
35
|
```erb
|
30
|
-
<%= clear_filter
|
36
|
+
<%= clear_filter title: 'Clear Filter', class: 'btn btn-primary', data: {confirm: 'Really?', my_data: 'something'} %>
|
31
37
|
```
|
32
38
|
|
33
39
|
## Configuration
|
34
40
|
|
35
|
-
|
41
|
+
Running ```rails generate ransack_memory``` the console will generate `config/initializers/ransack_memory.rb` with this content:
|
36
42
|
|
37
43
|
```ruby
|
38
44
|
RansackMemory::Core.config = {
|
@@ -41,8 +47,6 @@ RansackMemory::Core.config = {
|
|
41
47
|
}
|
42
48
|
```
|
43
49
|
|
44
|
-
Or you can generate this config file by running ```rails generate ransack_memory``` in console.
|
45
|
-
|
46
50
|
## Load saved filters from another controller action
|
47
51
|
|
48
52
|
In some cases, you want to load saved filters from another controller action. If so, you just create in the same controller this method:
|
@@ -57,7 +61,11 @@ Standard session key building is: ```"#{controller_name}_#{action_name}_#{reques
|
|
57
61
|
|
58
62
|
## Kaminari issue
|
59
63
|
|
60
|
-
When you have an issue with Kaminari gem, that you can't go back to the first page,
|
64
|
+
When you have an issue with Kaminari gem, that you can't go back to the first page, generate a kaminari configuration in the initializers folder
|
65
|
+
and set ```config.params_on_first_page = true```.
|
66
|
+
|
67
|
+
As an alternative update your kaminari view in `app/views/kaminari/_first_page.html.erb`:
|
61
68
|
```erb
|
62
69
|
<%= link_to_unless current_page.first?, t('views.pagination.first').html_safe, url_for(params.merge({page: 1, cancel_filter: nil})), remote: remote, class: 'btn btn-secondary' %>
|
63
70
|
```
|
71
|
+
However beware that this will probably lead to problems in later Rails versions due to a change in the way it allows you to merge parameters.
|
@@ -24,7 +24,7 @@ module RansackMemory
|
|
24
24
|
end
|
25
25
|
|
26
26
|
# search term saving
|
27
|
-
session["#{session_key_base}"] = params[::RansackMemory::Core.config[:param]] if params[::RansackMemory::Core.config[:param]].present?
|
27
|
+
session["#{session_key_base}"] = params[::RansackMemory::Core.config[:param]].to_h if params[::RansackMemory::Core.config[:param]].present?
|
28
28
|
|
29
29
|
# page number saving
|
30
30
|
session["#{session_key_base}_page"] = params[:page] if params[:page].present?
|
@@ -33,7 +33,7 @@ module RansackMemory
|
|
33
33
|
session["#{session_key_base}_per_page"] = params[:per_page] if params[:per_page].present?
|
34
34
|
|
35
35
|
# search term load
|
36
|
-
params[::RansackMemory::Core.config[:param]] = session["#{session_key_base}"].
|
36
|
+
params[::RansackMemory::Core.config[:param]] = session["#{session_key_base}"] if session["#{session_key_base}"].present?
|
37
37
|
|
38
38
|
# page number load
|
39
39
|
params[:page] = session["#{session_key_base}_page"].presence
|
@@ -42,12 +42,12 @@ module RansackMemory
|
|
42
42
|
params[:per_page] = session["#{session_key_base}_per_page"].presence
|
43
43
|
|
44
44
|
# set page number to 1 if filter has changed
|
45
|
-
if (params[::RansackMemory::Core.config[:param]].present? && session[:last_q_params] != params[::RansackMemory::Core.config[:param]]) || (params[:cancel_filter].present? && session["#{session_key_base}_page"] != params[:page])
|
45
|
+
if (params[::RansackMemory::Core.config[:param]].present? && session[:last_q_params] != params[::RansackMemory::Core.config[:param]].permit!.to_h) || (params[:cancel_filter].present? && session["#{session_key_base}_page"] != params[:page])
|
46
46
|
params[:page] = nil
|
47
47
|
session["#{session_key_base}_page"] = nil
|
48
48
|
end
|
49
49
|
|
50
|
-
session[:last_q_params] = params[::RansackMemory::Core.config[:param]]
|
50
|
+
session[:last_q_params] = params[::RansackMemory::Core.config[:param]]&.to_unsafe_h
|
51
51
|
|
52
52
|
# session[:last_page] = params[:page]
|
53
53
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ransack_memory
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Lapiš
|
@@ -36,17 +36,17 @@ require_paths:
|
|
36
36
|
- lib
|
37
37
|
required_ruby_version: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
|
-
- -
|
39
|
+
- - ">="
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: 1.9.3
|
42
42
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
|
-
- -
|
44
|
+
- - ">="
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '0'
|
47
47
|
requirements: []
|
48
48
|
rubyforge_project:
|
49
|
-
rubygems_version: 2.
|
49
|
+
rubygems_version: 2.6.13
|
50
50
|
signing_key:
|
51
51
|
specification_version: 3
|
52
52
|
summary: Automatically save and load ransack's filtered params into session
|