回答編集履歴

4

追記

2019/11/29 23:53

投稿

winterboum
winterboum

スコア23364

test CHANGED
@@ -57,3 +57,13 @@
57
57
  ```
58
58
 
59
59
  あたりでどうでしょう。。。
60
+
61
+
62
+
63
+ さらに追記
64
+
65
+ そこまでしないで良さそう
66
+
67
+ WillPagenate には @resources を渡し
68
+
69
+ データの描画には `@resources_sorted = @resources.sort{|a, b| a.code.to_i <=> b.code.to_i}` を使う

3

一部修正

2019/11/29 23:53

投稿

winterboum
winterboum

スコア23364

test CHANGED
@@ -52,9 +52,7 @@
52
52
 
53
53
  eval "def @resources.current_page ;#{@page} ;end
54
54
 
55
- def @resources.total_pages; #{total_pages} ; end
55
+ def @resources.total_pages; #{total_pages} ; end"
56
-
57
- current_page ;#{@page} ;end"
58
56
 
59
57
  ```
60
58
 

2

一部修正

2019/11/29 12:08

投稿

winterboum
winterboum

スコア23364

test CHANGED
@@ -46,15 +46,15 @@
46
46
 
47
47
  @resources = BookLibrary.paginate(:page => params[:page])
48
48
 
49
- count = @resources.count
50
-
51
49
  total_pages = @resources.total_pages
52
50
 
53
51
  @resources = @resources.sort{|a, b| a.code.to_i <=> b.code.to_i}
54
52
 
55
- eval "def @resources.count;#{count};end
53
+ eval "def @resources.current_page ;#{@page} ;end
56
54
 
57
- def @resources.total_pages; #{total_pages} ; end"
55
+ def @resources.total_pages; #{total_pages} ; end
56
+
57
+ current_page ;#{@page} ;end"
58
58
 
59
59
  ```
60
60
 

1

追記

2019/11/29 12:08

投稿

winterboum
winterboum

スコア23364

test CHANGED
@@ -1,3 +1,61 @@
1
1
  @resources = BookLibrary.order(:code).paginate(:page => params[:page])
2
2
 
3
3
  では駄目なのでしょうか?
4
+
5
+
6
+
7
+ 追記
8
+
9
+ こんなことやったことがあります。
10
+
11
+ ```
12
+
13
+ @Models = @Relation #.to_a
14
+
15
+
16
+
17
+ # ここから Will-Pagenatダマシ
18
+
19
+ # group(customer_id) を含む Relation#count が総数を返さず customer_id
20
+
21
+ # 毎の数を返すため、Cannot visit Customer::ActiveRecord_Relation や
22
+
23
+ # ActionView::Template::Error (undefined method `total_pages' なFaitalを
24
+
25
+ # 引き起こす。ので、
26
+
27
+ # view で呼ぶ will_paginate(@Models) のために
28
+
29
+ # @Models に method total_pages と current_page を定義する
30
+
31
+ # @models は pagenate を使わずに同じ結果となる検索を行なう。
32
+
33
+ eval "def @Models.count ; super.size ; end
34
+
35
+ def @Models.total_pages ; (self.count/#{@Pagenation.to_f}).ceil ; end
36
+
37
+ def @Models.current_page ;#{@page} ;end"
38
+
39
+ @models = @Models.offset((@page-1)*@Pagenation).limit(@Pagenation)
40
+
41
+ ```
42
+
43
+ とすると今回は
44
+
45
+ ```
46
+
47
+ @resources = BookLibrary.paginate(:page => params[:page])
48
+
49
+ count = @resources.count
50
+
51
+ total_pages = @resources.total_pages
52
+
53
+ @resources = @resources.sort{|a, b| a.code.to_i <=> b.code.to_i}
54
+
55
+ eval "def @resources.count;#{count};end
56
+
57
+ def @resources.total_pages; #{total_pages} ; end"
58
+
59
+ ```
60
+
61
+ あたりでどうでしょう。。。