1

フォローしているユーザーからの投稿を表示しようとしています。しかし、何らかの理由で、ストリーム インデックスに、私をフォローしているユーザーからの投稿が表示されます。フォローしているユーザーからの投稿を表示し、その逆を表示するにはどうすればよいですか? 前もって感謝します。

ユーザーモデル

has_many :following, :through => :relationships, :source => :followed
has_many :subscribed, class_name: "Relationship", foreign_key:  "follower_id"

投稿モデル

scope :subscribed, ->(following) { where user_id: following }

関係モデル

class Relationship < ActiveRecord::Base
  belongs_to :follower, class_name: "User"
  belongs_to :followed, class_name: "User"
  validates :follower_id, presence: true
  validates :followed_id, presence: true

  has_many :followed_users, through: :relationships, source: :followed

  #fields id | user_id | follower_id | created_at | updated_at
  belongs_to :user
end

ストリーム コントローラー

class StreamController < ApplicationController
  def index
    @posts = Post.subscribed current_user.following 
  end 
end

ストリーム インデックス

<div class="page-header">
  <center><strong><h1> Stream Page </h1></strong></center>
</div>

 <div id="posts" class="transitions-enabled">
  <% @posts.each do |post| %>

    <div class="box panel panel-default">
      <%= link_to image_tag(post.image.url(:medium)), post %>
      <div class="panel-body">
      <%= post.description %><br/>
      <strong><%= post.user.name if post.user %></strong>
     <% end %>
    </div>
    <% end %>
    </div> 
  <% end %>
 </div>
4

1 に答える 1