0

ここで読んだ内容をすべて上書きする「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: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

それから私の見解では

  <%= 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>
4

0 に答える 0