I'm using kaminari
for pagination.
Then I have 3 models such as User
, Community
, and Uniquecode
.
I'm facing the problem, in which the number of shown records varie(change) at each params[:page].
In addition, if I put <% @uniquecode_count %>
, it returns '1'...
Since there are 3 related records, it has to be '3', though.
This is really weird. In my case. I have related 3 Uniquecode records.
As I did put paginates_per 1
in Uniquecode model, it should show only 1 record at each page. However the result is
- At Page. 1 It shows 3 records
- At Page. 2 It shows 2 records
- At Page. 3 It shows 1 record
Why does do this? I never seen Kaminari doing this.
Can anyone help me to solve this?
I defined association like this
User has_many :communities
User has_many :uniquecodes
Community belongs_to :user
Community has_many :uniquecodes
Uniquecode belongs_to :user
Uniquecode belongs_to :community
uniquecode model
paginates_per 1
controller
@user = User.find(params[:id])
@uniquecodes = @user.uniquecodes.page(params[:page])
@uniquecodes_count = @uniquecodes.count
view
<%= paginate @uniquecodes, :window => 4 %>
<% @uniquecodes.recent.each do |uniquecode| %>
<%= render 'uniquecodes/uniquecode', :uniquecode => uniquecode %>
<% end %>
<% @uniquecode_count %> => this shows '1'. It has to show '3' though.