Ruby on rails will_paginate的用户变量似乎为空

Ruby on rails will_paginate的用户变量似乎为空,ruby-on-rails,pagination,will-paginate,Ruby On Rails,Pagination,Will Paginate,我正在关注无休止页面上的Railcast教程。我收到一个参数错误@users变量似乎为空。您是否忘记传递will_paginate的收集对象 javascript已被修改,因此您必须单击“阅读更多”链接才能获得更多结果。因此,分页将通过单击而不是滚动来工作 错误指向该行 问题: def index #Before gem added it was `@questions = Question.all` @questions = Question.order("ques

我正在关注无休止页面上的Railcast教程。我收到一个参数错误@users变量似乎为空。您是否忘记传递will_paginate的收集对象

javascript已被修改,因此您必须单击“阅读更多”链接才能获得更多结果。因此,分页将通过单击而不是滚动来工作

错误指向该行

问题:

      def index
#Before gem added it was `@questions = Question.all`
        @questions = Question.order("question").page(params[:users]).per_page(2)    
        respond_with(@questions)
    end
  def profile
    @profile = User.profile
    @user = User.find(params[:id]) 
    @question = Question.where(recipient_id: params[:id]).first
  end

  def show
    @user = User.find(params[:id])
    @question = Question.where(recipient_id: params[:id])
  end
用户控制器:

      def index
#Before gem added it was `@questions = Question.all`
        @questions = Question.order("question").page(params[:users]).per_page(2)    
        respond_with(@questions)
    end
  def profile
    @profile = User.profile
    @user = User.find(params[:id]) 
    @question = Question.where(recipient_id: params[:id]).first
  end

  def show
    @user = User.find(params[:id])
    @question = Question.where(recipient_id: params[:id])
  end
视图:

问题:咖啡:

jQuery ->
  if $('.pagination').length
    $('#append_and_paginate').prepend('<a id="append_more_results" href="javascript:void(0);">Show more questions</a>');
    $('#append_more_results').click ->
      url = $('.pagination .next_page').attr('href')
      if url
        $('.pagination').text('Fetching more questions...')
        $.getScript(url)
Index.js.erb:

$('#questions').append('<%= j render(@questions) %>');
<% if @questions.next_page %>
  $('.pagination').replaceWith('<%= j will_paginate(@questions) %>');
<% else %>
  $('#append_and_paginate').remove();
<% end %>
<% sleep 1 %>
替换

    @questions = Question.order("question").page(params[:users]).per_page(2)    

编辑

更新用户模型,如下所示:

class User < ActiveRecord::Base

  has_many :sender_questions, :class_name => 'Question', :foreign_key => 'sender_id' 
  has_many :recipient_questions, :class_name => 'Question', :foreign_key => 'recipient_id'

end
def show
  @user = User.find(params[:id]) 
  @question = @user. recipient_questions.paginate(page: params[:page])
end

您能否分享问题中的错误stacktrace。您似乎正在调用其中一个视图中的will_paginate@users,并且未设置@users。如果在问题中提供stacktace,则更容易解决问题。仅当问题的答案不为空时,才会显示错误。对于其他测试帐户,他们尚未回答的问题会加载配置文件,但是一旦我添加了答案,页面就会显示出相同的错误。在我的用户控制器中,如果我将@question=question.whererecipient_id:params[:id]更改为@question=@user.Questions.paginatepage:params[:id],则会添加此错误我得到错误Mysql2::error:Unknown列'questions.user\u id'在'where子句':从'questions'where'questions'中选择'questions`.''user\u id`=2限制30偏移量30,因此我需要从存在的recipient\u id列读取它。您在该问题中共享的视图的名称是什么?