Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何在rails中使用will_paginate在我的视图中显示两种不同的模型?_Ruby On Rails_Ruby On Rails 3_Display_Will Paginate - Fatal编程技术网

Ruby on rails 如何在rails中使用will_paginate在我的视图中显示两种不同的模型?

Ruby on rails 如何在rails中使用will_paginate在我的视图中显示两种不同的模型?,ruby-on-rails,ruby-on-rails-3,display,will-paginate,Ruby On Rails,Ruby On Rails 3,Display,Will Paginate,大家好,我有一个问题,我在谷歌上寻找,但我没有找到答案。 我实际上想通过搜索在同一个页面中显示帖子模型和用户模型,为此我想使用Will_paginate来显示所有这些模型。 我尝试这个解决方案=> **require 'will_paginate/array' @posts =Post.search(params[:q]).order("created_at DESC") @users=User.search(params[:q]).order("created_at DESC")

大家好,我有一个问题,我在谷歌上寻找,但我没有找到答案。 我实际上想通过搜索在同一个页面中显示帖子模型和用户模型,为此我想使用Will_paginate来显示所有这些模型。 我尝试这个解决方案=>

  **require 'will_paginate/array'
  @posts =Post.search(params[:q]).order("created_at DESC")
  @users=User.search(params[:q]).order("created_at DESC")
    @all_records = (@posts + @users).paginate(:page =>params[:page], :per_page => 10)**
在我的视图中,我想显示找到的所有查询,所以我尝试这样做=>

 **<%unless @posts.nil?%>
  <% @posts.each do |post| %>
  ....
**
**<% unless @users.nil?%>
<% @users.each do |user| %>
...**
<%= will_paginate @all_records %>
**
....
**
**
...**
但它不起作用,所以我想知道如何在@all_记录中获取@posts和@users记录,以执行类似的操作=> **


** 我看到一些解决方案建议在我看来使用两种不同的分页方式,如=>

**<%= will_paginate @posts %>
<%= will_paginate @users %>**
**
**
**但这不是我想要的,我只想要一个分页,请帮帮我,因为我快疯了,谢谢**

我遵循这个教程,因为我认为使用ajax无限滚动显示两个模型分页更容易,但什么都没有发生,我的控制器没有进入我的index.js.erb,我不知道为什么,我尝试更改位置值,但没有任何帮助请遵循本教程,因为我认为使用ajax无限滚动显示两个模型分页更容易,但什么也没有发生,我的控制器没有进入我的index.js.erb,我不知道为什么,我尝试更改位置值,但没有任何帮助
**<%= will_paginate @posts %>
<%= will_paginate @users %>**