メッセージページのコメント一覧にpaginate(kaminari)を以下のように追加したのですが、
paginateの欄だけ表示されてページ移動してもコメント一覧に何も変化がなく機能しません。
どうしたらコメント3つ目以降はpaginateに反映されるでしょうか
###該当のソースコード
message_controller.rb def show @comments = @message.comments.page(params[:page]).per(3) end
messages/show.html.erb <%= render @message.comments %> <%= paginate @comments %>
mingosが👍を押しています
気になる質問をクリップする
クリップした質問は、後からいつでもMYページで確認できます。
またクリップした質問に回答があった際、通知やメールを受け取ることができます。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
回答2件
0
コードは問題なさそう。。
データがおかしいということはありませんか?
@message.commentsがあやしいですね。。
p @message.comments.page.to_sql
で発行SQLを見てみてください。
原因が分かるはずです。
投稿2017/03/30 04:44
編集2017/03/30 04:45総合スコア155
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
Started GET "/messages/1" for 60.237.45.180 at 2017-03-30 06:29:26 +0000
Cannot render console from 60.237.45.180! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
Processing by MessagesController#show as HTML
Parameters: {"id"=>"1"}
Message Load (0.4ms) SELECT "messages".* FROM "messages" WHERE "messages"."id" = ? LIMIT ? [["id", 1], ["LIMIT", 1]]
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ? [["id", 100], ["LIMIT", 1]]
Comment Load (0.3ms) SELECT "comments".* FROM "comments" WHERE "comments"."message_id" = ? LIMIT ? OFFSET ? [["message_id", 1], ["LIMIT", 25], ["OFFSET", 0]]
#<ActiveRecord::AssociationRelation [#<Comment id: 1, content: "Hi!!!!", message_id: 1, user_id: 1, created_at: "2017-03-25 06:29:32", updated_at: "2017-03-25 06:29:32">, #<Comment id: 2, content: "Hey !!!", message_id: 1, user_id: 100, created_at: "2017-03-26 01:19:13", updated_at: "2017-03-26 01:19:13">, #<Comment id: 3, content: "wadadoak", message_id: 1, user_id: 1, created_at: "2017-03-30 05:53:19", updated_at: "2017-03-30 05:53:19">, #<Comment id: 4, content: "csclspclspc", message_id: 1, user_id: 1, created_at: "2017-03-30 05:53:26", updated_at: "2017-03-30 05:53:26">, #<Comment id: 5, content: "lpcldpldpcldpl", message_id: 1, user_id: 1, created_at: "2017-03-30 05:53:32", updated_at: "2017-03-30 05:53:32">, #<Comment id: 6, content: "vfokvfokvf", message_id: 1, user_id: 100, created_at: "2017-03-30 06:07:42", updated_at: "2017-03-30 06:07:43">, #<Comment id: 7, content: "lpvlpclvp", message_id: 1, user_id: 100, created_at: "2017-03-30 06:07:49", updated_at: "2017-03-30 06:07:49">, #<Comment id: 8, content: "lplplvpflvpflvpf", message_id: 1, user_id: 100, created_at: "2017-03-30 06:07:55", updated_at: "2017-03-30 06:07:55">, #<Comment id: 9, content: "lplvbbvbvbll", message_id: 1, user_id: 100, created_at: "2017-03-30 06:08:03", updated_at: "2017-03-30 06:08:03">]>
Rendering messages/show.html.erb within layouts/application
ActsAsTaggableOn::Tagging Load (0.3ms) SELECT "taggings".* FROM "taggings" WHERE "taggings"."taggable_id" = ? AND "taggings"."taggable_type" = ? [["taggable_id", 1], ["taggable_type", "Message"]]
ActsAsTaggableOn::Tag Load (0.3ms) SELECT "tags".* FROM "tags" INNER JOIN "taggings" ON "tags"."id" = "taggings"."tag_id" WHERE "taggings"."taggable_id" = ? AND "taggings"."taggable_type" = ? AND (taggings.context = 'games' AND taggings.tagger_id IS NULL) [["taggable_id", 1], ["taggable_type", "Message"]]
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ? [["id", 1], ["LIMIT", 1]]
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ? [["id", 1], ["LIMIT", 1]]
Comment Load (0.3ms) SELECT "comments".* FROM "comments" WHERE "comments"."message_id" = ? [["message_id", 1]]
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ? [["id", 1], ["LIMIT", 1]]
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ? [["id", 1], ["LIMIT", 1]]
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ? [["id", 100], ["LIMIT", 1]]
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ? [["id", 100], ["LIMIT", 1]]
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ? [["id", 1], ["LIMIT", 1]]
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ? [["id", 1], ["LIMIT", 1]]
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ? [["id", 1], ["LIMIT", 1]]
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ? [["id", 1], ["LIMIT", 1]]
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ? [["id", 1], ["LIMIT", 1]]
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ? [["id", 1], ["LIMIT", 1]]
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ? [["id", 100], ["LIMIT", 1]]
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ? [["id", 100], ["LIMIT", 1]]
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ? [["id", 100], ["LIMIT", 1]]
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ? [["id", 100], ["LIMIT", 1]]
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ? [["id", 100], ["LIMIT", 1]]
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ? [["id", 100], ["LIMIT", 1]]
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ? [["id", 100], ["LIMIT", 1]]
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ? [["id", 100], ["LIMIT", 1]]
Rendered collection of comments/_comment.html.erb [9 times] (17.9ms)
Rendered comments/_form.html.erb (7.0ms)
Rendered messages/show.html.erb within layouts/application (44.2ms)
Completed 200 OK in 178ms (Views: 114.2ms | ActiveRecord: 6.9ms)
このように出ました
どのようにしたらよろしいでしょうか
あなたの回答
tips
太字
斜体
打ち消し線
見出し
引用テキストの挿入
コードの挿入
リンクの挿入
リストの挿入
番号リストの挿入
表の挿入
水平線の挿入
プレビュー
質問の解決につながる回答をしましょう。 サンプルコードなど、より具体的な説明があると質問者の理解の助けになります。 また、読む側のことを考えた、分かりやすい文章を心がけましょう。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。