rails undefined局部变量或方法`page'

时间:2016-06-30 16:49:57

标签: ruby-on-rails-4

我有一个如下所示的寻呼机,它返回错误"未定义的局部变量或方法`page' for ...:

    <nav>
    <ul class="pager">
        <li class="previous <%= page == 0 ? 'display' : 'hidden' %>">
            <%= link_to_if page > 0, "&larr; Previous".html.safe,
                users_path(keywords: keywords, page: page - 1) %>
        </li>
        <li class="next">
            <<%= link_to "Next &rarr;".html.safe,
                users_path(keywords: keywords, page: page + 1) %>
        </li>
    </ul>
</nav>

使用<% render "pager", locals: { keywords: @keywords, page: @page } %>

进行调用

关联的控制器是

PAGE_SIZE = 20

def index
    @page = (params[:page] || 0).to_i

    if params[:keywords].present?
        @keywords = params[:keywords]
        user_search_term = UserSearchTerm.new(@keywords)
        @users = User.where(
            user_search_term.where_clause,
            user_search_term.where_args).
            order(user_search_term.order).
            offset(PAGE_SIZE * @page).limit(PAGE_SIZE)
    else

我做错了什么?

1 个答案:

答案 0 :(得分:0)

您可以尝试使用<% render partial: "pager", locals: { keywords: @keywords, page: @page } %>

如果您不使用partial,则也不需要使用locals