当前位置: 动力学知识库 > 问答 > 编程问答 >

ruby on rails - Why do I get this error when I try to use pagination?

问题描述:

There are 3 models such as User, Community, and Uniquecode.

Then I'm using kaminari for pagination.

I'm getting this error.

undefined local variable or method `uniquecode'

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

community model

def self.not_deleted

where deleted_at: nil

end

controller

@user = User.find(params[:id])

@uniquecodes = Uniquecode.where(uniquecodes.user_id => @user.id).joins(:community).merge(Community.not_deleted).page(params[:page]).order("uniquecodes.updated_at DESC")

@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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: