Ruby on rails 如何让paginate工作,而不是重定向到';public/index.html';?
我的主页使用“public/index.html”,它覆盖了我在这里读到的所有内容 因此,我已将所有登录用户重定向到Ruby on rails 如何让paginate工作,而不是重定向到';public/index.html';?,ruby-on-rails,ruby,pagination,will-paginate,Ruby On Rails,Ruby,Pagination,Will Paginate,我的主页使用“public/index.html”,它覆盖了我在这里读到的所有内容 因此,我已将所有登录用户重定向到http://localhost:3000/home我在我的路线中定义为get'/home'=>“static_pages#home',:as=>:home 我面临的问题是,在登录用户(/home)的主页上有分页 当我试图点击第2页http://localhost:3000/?page=2,它将被发送到public/index.html 我尝试了链接http://localhost
http://localhost:3000/home
我在我的路线中定义为get'/home'=>“static_pages#home',:as=>:home
我面临的问题是,在登录用户(/home)的主页上有分页
当我试图点击第2页http://localhost:3000/?page=2
,它将被发送到public/index.html
我尝试了链接http://localhost:3000/home/?page=2
作为测试,但它给我一个空白分页。不显示任何项目。我怎样才能解决这个问题
这是控制器
class StaticPagesController < ApplicationController
def home
if signed_in?
@post = current_user.microposts.build
@activities = PublicActivity::Activity.order("created_at desc").paginate(page: params[:page])
@feed_items = current_user.feed.paginate(page: params[:page])
@items = @activities + @feed_items
@items.sort_by{|item| item.class == PublicActivity::Activity ? item.created_at : item.created_at}
@items = @items.paginate(:page => 1, :per_page => 10)
else
redirect_to root_path
end
end
class StaticPagesController1,:per_page=>10)
其他的
将\重定向到根\路径
结束
结束
那么在我看来,
<%= render partial: 'shared/item', collection: @items %>
<%= will_paginate @items %>
这是_item.html.erb部分
<li id="<%= item.id %>">
<% if item.class == PublicActivity::Activity %>
<% if item.trackable_type == "Micropost" %>
<%= link_to item.owner.name, item.owner if item.owner %><span class="textname"> posted</span>
<% else %>
<%= link_to item.owner.name, item.owner if item.owner %><span class="textname"> made a comment </span>
<% end %>
<% else %>
<br>
<div class ="gravatarhome"><%= link_to gravatar_for(item.user), item.user %></div>
<%= link_to item.user.name, item.user %>
<span class="textname">shared this
<div class="FeedContent"><%= truncate(item.content, :length=>150, :omission=>' ...(continued)') %>
<% end %>
</li>
分享这个
150,:省略=>'…(续)%>
分页时使用的是什么?你能发布你的相关控制器操作和你的分页链接所在的视图部分吗?我发布了相关信息。你想同时看到_item.html.erb部分吗?@hd1我刚刚发布了_item部分。这就是我试图分页的内容,显示在“www.mydomain.com/home”上,但由于我有public/index.html,http://www.mydomain.com/?page=2
这使我回到public/index.html文件