質問編集履歴

2

文章

2019/11/13 03:22

投稿

uooyr
uooyr

スコア6

test CHANGED
File without changes
test CHANGED
@@ -88,7 +88,9 @@
88
88
 
89
89
  ```
90
90
 
91
+ Gem
91
92
 
93
+ ---
92
94
 
93
95
  ```gem
94
96
 

1

コード追加

2019/11/13 03:22

投稿

uooyr
uooyr

スコア6

test CHANGED
File without changes
test CHANGED
@@ -1,11 +1,99 @@
1
1
  Railsでページネーションを実装したく
2
2
 
3
- kaminariというgemをGemFlieに記述し、bundle installを実行したのですが
3
+ kaminariというgemをGemFlieに記述し、bundle installを実行し
4
+
5
+ ```
6
+
7
+ def index
8
+
9
+ @posts = Post.page(params[:page])
10
+
11
+ end
12
+
13
+ ```
14
+
15
+ のようにコードを書きlocalhostでアクセスすると
4
16
 
5
17
  「 undefined method `page' for #<Class:0x0000000003cddf68> 」
6
18
 
7
19
  というエラーが出ます。
8
20
 
9
- pageメソ使えいということだと思うのです
21
+ トで調べても同じようなエラーの対処法見つからかったです
10
22
 
11
23
  解決方法ありますでしょうか。
24
+
25
+ index.htm.erb
26
+
27
+ ---
28
+
29
+ ```html
30
+
31
+ <p id="notice"><%= notice %></p>
32
+
33
+
34
+
35
+ <h1>ミニブログサイト</h1>
36
+
37
+
38
+
39
+ <table>
40
+
41
+ <thead>
42
+
43
+ <tr>
44
+
45
+ <th>タイトル</th>
46
+
47
+ <th>本文</th>
48
+
49
+ <th>投稿日</th>
50
+
51
+ <th colspan="3"></th>
52
+
53
+ </tr>
54
+
55
+ </thead>
56
+
57
+
58
+
59
+ <tbody>
60
+
61
+
62
+
63
+ <% @posts.each do |post| %>
64
+
65
+ <tr>
66
+
67
+ <td><%= link_to post.title, post %></td>
68
+
69
+ <td><%= post.content .truncate(200)%></td>
70
+
71
+ <td><%= post.created_at %></td>
72
+
73
+ </tr>
74
+
75
+ <% end %>
76
+
77
+ </tbody>
78
+
79
+ </table>
80
+
81
+ <%= paginate @posts %>
82
+
83
+ <br>
84
+
85
+
86
+
87
+ <%= link_to '新規投稿', new_post_path %>
88
+
89
+ ```
90
+
91
+
92
+
93
+ ```gem
94
+
95
+ gem 'kaminari'
96
+
97
+ gem 'kaminari-i18n'
98
+
99
+ ```