1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Rails】連動しないwill_paginateの設定

Last updated at Posted at 2020-03-30
static_pages_controller.rb
:
@myfeed_items = current_user.myfeed.paginate(page: params[:page], per_page: 3)
@followingfeed_items = current_user.followingfeed.paginate(page: params[:page], per_page: 3)
:

上記のように同様のファイルにwill_paginateの設定がされているときに、両方とも連動してページが動いてしまいます。

image.png

image.png

#解決策

static_pages_controller.rb
:
@myfeed_items = current_user.myfeed.paginate(page: params[:myfeed_items_page], per_page: 3)
@followingfeed_items = current_user.followingfeed.paginate(page: params[:followingfeed_items_page], per_page: 3)
:

上記のようにpage: params[任意の値]に設定することで連動を防ぐことができます。

_myfeed.html.erb
:
  <%= will_paginate @myfeed_items, :param_name => 'myfeed_items_page', class: "center" %>
:
_followingfeed.html.erb
:
  <%= will_paginate @followingfeed_items, :param_name => 'followingfeed_items_page', class: "center" %>
:

それぞれのhtml.erbも修正すればwill_paginateで設定されているボタンが単独で動いてくれます。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?